Bash Tips And Tricks
Send Graphical Notifications To Your ScreenUsing notify-send, you can send brief notifications to your screen. Useful for polling web information or if your writing a script and at the end you want the user to know it has completed
First make sure you have the software you need sudo apt-get install libnotify-bin
To send a message type in a console: notify-send "THIS IS A NOTIFICATION"
Instead of plain test you can notify the output of a command by enclosing your command like this: notify-send "`uptime`"
Common Options are:
-t (Time in milliseconds to show the notification)
-u [low/normal/critical] (Set the urgency level)
-i (Set a specific icon to show with the notification)
Making Bash Scripts and Outputs More Visually AppealingAs part of all linux OS's tput is a neat tool to make scripts and output messages with. You can control where the cursor is, color of text, style of text and generally give a little pizzaz to bash scripts that require user input. Ill just do a simple menu based script and put enough comments inline to give you a rough idea.
Dialog The Ultimate BASH GUII love the console and running command line interfaces and commands. And the nicer you can make an interface the easier it is for a user to use it. Tput example above helps with basics but when it comes to more full looking scripts you might want to switch to dialog. There is every input and output form you can imagine available to view all option run man dialog in a console. You can use the little script I have done below as a quick guide.
Logging Output To System LogWhile working on scripts its good to output errors and sometimes sucess messages to the main system log. This can easily be accomplished with the "logger" command. Simply add the command
to your script file to have MESSAGE_TO_ADD added to /var/log/syslog. You can add a -t and a name to the command to specify the program. This makes it easier to look for messages just for that program in case something goes wrong. For instance if your writing a backup script you might want to use:
logger -t BACKUP "Backup for system failed"
Now if you need to look at any output logs from your backups you can grep BACKUP /var/log/syslog and all instanced will show.