Check These Out
If you want to operate on a set of items in Bash, and at least one of them contains spaces, the `for` loop isn't going to work the way you might expect. For example, if the current dir has two files, named "file" and "file 2", this would loop 3 times (once each for "file", "file", and "2"):
$ for ITEM in `ls`; do echo "$ITEM"; done
Instead, use a while loop with `read`:
$ ls | while read ITEM; do echo "$ITEM"; done
Usage: lower [STRING]...
Converts any number of seconds into days, hours, minutes and seconds.
sec2dhms() {
declare -i SS="$1"
D=$(( SS / 86400 ))
H=$(( SS % 86400 / 3600 ))
M=$(( SS % 3600 / 60 ))
S=$(( SS % 60 ))
[ "$D" -gt 0 ] && echo -n "${D}:"
[ "$H" -gt 0 ] && printf "%02g:" "$H"
printf "%02g:%02g\n" "$M" "$S"
}
Usefull for when you don't have nmap and need to find a missing host.
Pings all addresses from 10.1.1.1 to 10.1.1.254, modify for your subnet.
Timeout set to 1 sec for speed, if running over a slow connection you should raise that to avoid missing replies.
This will clean up the junk, leaving just the IP address:
for i in {1..254}; do ping -c 1 -W 1 10.1.1.$i | grep 'from' | cut -d' ' -f 4 | tr -d ':'; done
This version eliminates the grep before the awk, which is always good. It works for GNU core utils and ensures that the date output of ls matches the format in the pattern match, regardless of locale, etc.
On BSD-based systems, you can easily eliminate both the grep and the awk:
find . -maxdepth 1 -Btime -$(date +%kh%lm) -type f
Run CPU benchmark from command line
parallel can be installed on your central node and can be used to run a command multiple times.
In this example, multiple ssh connections are used to run commands. (-j is the number of jobs to run at the same time). The result can then be piped to commands to perform the "reduce" stage. (sort then uniq in this example).
This example assumes "keyless ssh login" has been set up between the central node and all machines in the cluster.
bashreduce may also do what you want.
"Copying" things to the X clipboard doesn't normally create a copy. Rather the data to be 'copied' is referenced. This means that if the application that you 'copied' stuff from is closed, that data is lost. If the application that you 'copied' from is suspended with CTRL-Z, there could be some issues if you try to paste it into something.
This command will create a copy of referenced data and have xclip be the provider of it, so you can then go ahead and close the app that contains the original information.
Caveat: I'm not sure if this is binary-safe (though i would expect it to be), and don't know what would happen if you used it to clip a 20 meg gimp image.
This technique becomes more convenient if you set it up as an action in a clipboard manager (eg klipper, parcellite). Some of these applets can take automatic action based on a variety of parameters, so you could probably just get it to always own the clipped data whenever data is clipped.