December 7, 2008 -
Lately I installed rsnapshot on my lappy to get my files backed up on my home server during the night, in case the laptop is on.
Rsnapshot is only CLI, I still somewhat wanted to get some kind of visual notification saying the backup was starting (and ending).. just to avoid shutting down my machine while the backup process was still on, for example.
Rsnapshot allows you, throught the cmd_postexec and cmd_preexec options, to run scripts before and after the backup job.
I came up with scripts using Zenity for visual notifications.
The thing is, the cmd_postexec script must complete before the backup can begin, and the only documented way I found to start the backup was to click OK on the zenity notification. This would be annoying if I’m not at the computer at that time (which is very likely
). The notification popup would just wait for my input to start the backup job.. not good.
I tried to figure out a decent way to get rid of the popup after a few second, but I didn’t have to search for too long.. Indeed, Marco spotted that Zenity has an undocumented timeout option doing exactly what I wanted.
Odd that it is not documented..
Thanks to Marco !
For the curious, here’s the cmd_postexec script (rsnapshot running as root and opening the popup on the user’s desktop) :
#!/bin/bash
su USERNAME -c 'export DISPLAY=:0.0; zenity --timeout 30 --info --text "Rsnapshot backup will start in 30 seconds"'
exit 0
May 24, 2008 -
A bit of explanations :
$ help disown
disown: disown [-h] [-ar] [jobspec ...]
By default, removes each JOBSPEC argument from the table of active jobs.
If the -h option is given, the job is not removed from the table, but is
marked so that SIGHUP is not sent to the job if the shell receives a
SIGHUP. The -a option, when JOBSPEC is not supplied, means to remove all
jobs from the job table; the -r option means to remove only running jobs.
And a slice of example :
1. Let’s open a terminal
2. We launch a very long process in background : ./myprocess.sh &
3. We type : disown XXXX where XXXX is the PID of the bash command running myprocess.sh
4. We close the terminal
5. We open a new terminal, we type “ps faux” and notice myprocess.sh is still running
It’s possible to start the command like this : “./myprocess.sh & disown”
disown allows you to detach a process from the currently running bash session, this can come in handy if you forgot to launch the process in a screen session or with nohup and you need to close the current session.
If you want to make some tests, myprocess.sh could look like this :
#!/bin/bash
until [ ! blah ]; do sleep 1; done
Links :
nohup : http://www.wains.be/index.php/2007/08/26/nohup/
screen : http://www.gnu.org/software/screen/
-
In this post I was describing how one can share a bash session using a named pipe.
This is a great way if you can’t install anything on the machine. If you are able to get “screen” installed, screen provides a much easier way, which allows all connected users to interact on the shared session. The named pipe method only allowed one user to watch what the other user was doing.
So here it goes…
1. user 1 connects to the machine and type the command “screen”
2. inside the screen terminal, user 1 hits ctrl + a and then type “:multiuser on”
3. user 2 joins in by typing “screen -x”
4. other users can join as described at point 3
Both users are now sharing the session.
Ctrl + a then d will close the screen session
Links :
Source : http://linuxhelp.blogspot.com/2005/01/screen-window-manager-for-console.html
Putting a password on a screen session : http://www.wains.be/index.php/2007/07/23/put-a-password-on-your-screen-session/
November 26, 2007 -
Richard posted some nice tips about bash history..
I’ll post his tips here in a shorter version
The following snippets of code must be added to your .bashrc file.
You open two terminals, when closing them, history of only one of both is saved ?
This is the fix, that will merge/append histories from both terminals in the history :
shopt -s histappend
PROMPT_COMMAND=’history -a’
Avoiding spelling mistakes (like /ect instead of /etc) :
shopt -s cdspell
Disable duplicate entries in history (this is the default under Ubuntu) :
export HISTCONTROL="ignoredups"
I’m adding a new one, same as above. ignorespace won’t store in history every command started by a space. Nice when you need to type sensitive info at the CLI.
export HISTCONTROL=ignoredups:ignorespace
Remove ls, fg, bg and exit commands from history :
export HISTIGNORE="&:ls:[bf]g:exit"
Multiple line commands split up in history :
shopt -s cmdhist
October 23, 2007 -
Under Debian or RHEL4 and later, it can be as simple as :
$ date -d @1193144433
Tue Oct 23 15:00:33 CEST 2007
But that command doesn’t work under Redhat EL 3, so you should use the following :
$ date --date "1970-01-01 1193144433 sec" "+%Y-%m-%d %T"
2007-10-23 15:00:33
The output is different though
You can always use the previous command under Ubuntu/RHEL4+ or the simpler :
$ date -d @1193144433 "+%Y-%m-%d %T"
2007-10-23 15:00:33
Converting a date to unix timestamp :
$ date -d "2007-10-23 15:00:23" "+%s"
1193144423
Add "--utc" to the commands if you want to get the UTC time.
September 3, 2007 -
My friend Jonathan just passed me another nice CLI tip
Sometimes, some commands output are not really readable :
Example :
$ mount
Readability can be improved by piping “mount” into the command “column”
$ mount | column -t
There are so many little useful commands like these under Linux, I wish I knew them all.
Any other similar tips are welcomed !
August 26, 2007 -
See http://en.wikipedia.org/wiki/Nohup
nohup is a Unix command that is used to run another command while suppressing the action of the HUP (hangup) signal, enabling the command to keep running after the user who issues the command has logged out. It is most often used to run commands in background as daemons. Output that would normally go to the terminal goes to a file called nohup.out if it has not already been redirected.
Example :
$ nohup gedit &
nohup: appending output to `nohup.out'
I can now close the terminal from which I launched gedit, gedit will keep running. Without nohup, gedit would close along with the terminal.
$ cat nohup.out
This would display what was supposed to be output to the terminal..
Anyway, this post is just for the record, because I’m using screen which is a better alternative
December 18, 2006 -
Great memo !
Original link
25 March 2007 : New memo from http://linuxhelp.blogspot.com/2005/08/bash-shell-shortcuts.html
CTRL Key Bound
Ctrl + a – Jump to the start of the line
Ctrl + b – Move back a char
Ctrl + c – Terminate the command
Ctrl + d – Exit the current shell
Ctrl + e – Jump to the end of the line
Ctrl + f – Move forward a char
Ctrl + h – Same as backspace
Ctrl + k – Delete to EOL
Ctrl + l – Clear the screen
Ctrl + r – Search the history backwards
Ctrl + R – Search the history backwards with multi occurrence
Ctrl + t : Swap the last two characters before the cursor
Ctrl + u – Delete backward from cursor
Ctrl + w : Delete the word before the cursor
Ctrl + xx – Move between EOL and current cursor position
Ctrl + x @ – Show possible hostname completions
Ctrl + z – Suspend/ Stop the command. “fg” restores the suspended command.
ALT Key Bound
Alt + < - Move to the first line in the history
Alt + > – Move to the last line in the history
Alt + ? – Show current completion list
Alt + * – Insert all possible completions
Alt + / – Attempt to complete filename
Alt + . – Yank last argument to previous command
Alt + b – Move backward
Alt + c – Capitalize the word
Alt + d – Delete word
Alt + f – Move forward
Alt + l – Make word lowercase
Alt + n – Search the history forwards non-incremental
Alt + p – Search the history backwards non-incremental
Alt + r – Recall command
Alt + t – Move words around
Alt + u – Make word uppercase
Alt + back-space – Delete backward from cursor
More Special Keybindings
Here “2T” means Press TAB twice
$ 2T – All available commands(common)
$ (string)2T – All available commands starting with (string)
$ /2T – Entire directory structure including Hidden one
$ 2T – Only Sub Dirs inside including Hidden one
$ *2T – Only Sub Dirs inside without Hidden one
$ ~2T – All Present Users on system from “/etc/passwd”
$ $2T – All Sys variables
$ @2T – Entries from “/etc/hosts”
$ =2T – Output like ls or dir
November 14, 2006 -
Delete files in the current directory above 500Kb
find -size +500 | xargs rm
This may not work on files with spaces in their filename. Use the solution recommended in the comments.
Other recipes :
Change the permissions and set 750 on dirs and 0640 on files:
find -type d -exec chmod 0750 '{}' ';'
find -type f -exec chmod 0640 '{}' ';'
November 13, 2006 -
“Permission denied (publickey,keyboard-interactive)”
I’m not satisfied by SSH clients under Linux (like putty and the likes), the only ssh client I really enjoy is SecureCRT under Windows, it’s a great piece of software (okay it works with wine, I have tested it, but I want to stick withthe CLI under Linux).
SSH agent forwarding ?
Next Page »