Check These Out
Very useful in shell scripts because you can run a task nicely in the background using job-control and output progress until it completes.
Here's an example of how I use it in backup scripts to run gpg in the background to encrypt an archive file (which I create in this same way). $! is the process ID of the last run command, which is saved here as the variable PI, then sleeper is called with the process id of the gpg task (PI), and sleeper is also specified to output : instead of the default . every 3 seconds instead of the default 1. So a shorter version would be sleeper $!;
The wait is also used here, though it may not be needed on your system.
$ echo ">>> ENCRYPTING SQL BACKUP"
$ gpg --output archive.tgz.asc --encrypt archive.tgz 1>/dev/null &
$ PI=$!; sleeper $PI ":" 3; wait $PI && rm archive.tgz &>/dev/null
Previously to get around the $! not always being available, I would instead check for the existance of the process ID by checking if the directory /proc/$PID existed, but not everyone uses proc anymore. That version is currently the one at http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html but I plan on upgrading to this new version soon.
Using this command you can track a moment when usb device was attached.
Especially useful to gauge the performance of a VPS.
Using this command you can track a moment when usb device was attached.
This loop will finish if a file hasn't changed in the last 10 seconds.
.
It checks the file's modification timestamp against the clock.
If 10 seconds have elapsed without any change to the file, then the loop ends.
.
This script will give a false positive if there's a 10 second delay between updates,
e.g. due to network congestion
.
How does it work?
'date +%s' gives the current time in seconds
'stat -c %Y' gives the file's last modification time in seconds
'$(( ))' is bash's way of doing maths
'[ X -lt 10 ]' tests the result is Less Than 10
otherwise sleep for 1 second and repeat
.
Note: Clever as this script is, inotify is smarter.
Requires perl 5.14 or greater
Number of files in a SVN Repository
This command will output the total number of files in a SVN Repository.