Check These Out
Only useful for really flakey connections (but im stuck with one for now). Though if youre in this situation ive found this to be a good way to run autossh and it does a pretty good job of detecting when the session is down and restarting. Combined with the -t and screen commands this pops you back into your working session lickety split w/ as few headaches as possible.
And if autossh is a bit slow at detecting the downed ssh connection, just run this in another tab/terminal window to notify autossh that it should drop it and start over. Basically for when polling is too slow.
kill -SIGUSR1 `pgrep autossh`
underline() will print $1, followed by a series of '=' characters the width of $1. An optional second argument can be used to replace '=' with a given character.
This function is useful for breaking lots of data emitted in a for loop into sections which are easier to parse visually. Let's say that 'xxxx' is a very common pattern occurring in a group of CSV files.
You could run
$ grep xxxx *.csv
This would print the name of each csv file before each matching line, but the output would be hard to parse visually.
$ for i in *.csv; do printf "\n"; underline $i; grep "xxxx" $i; done
Will break the output into sections separated by the name of the file, underlined.
From the 'disown' man page:
disown prevents the current shell from sending a HUP signal to each of the given jobs when the current shell terminates a login session.
The output format is given by the -printf parameter:
%T@ = modify time in seconds since Jan. 1, 1970, 00:00 GMT, with fractional part. Mandatory, hidden in the end.
%TY-%Tm-%Td %TH:%TM:%.2TS = modify time as YYYY-MM-DD HH:MM:SS. Optional.
%p = file path
Refer to http://linux.die.net/man/1/find for more about -printf formatting.
------------------------
sort -nr = sort numerically and reverse (higher values - most recent timestamp - first)
head -n 5 = get only 5 first lines (change 5 to whatever you want)
cut -f2- -d" " = trim first field (timestamp, used only for sorting)
------------------------
Very useful for building scripts for detecting malicious files upload and malware injections.
This command create a new temp directory using mktemp (to avoid collisions) and change the current working directory to the created directory.
Looking for carriage returns would also identify files with legacy mac line endings. To fix both types:
$ perl -i -pe 's/\r\n?/\n/g' $(find . -type f -exec fgrep -l $'\r' "{}" \;)
Use `zless` to read the content of your *rss.gz file:
$ zless commandlinefu-contribs-backup-2009-08-10-07.40.39.rss.gz
I have a remote php file that I want to run once an hour. I set up cron to run this wget. I don't really care about what's in the file though, I don't want to save the results, so I run the -O and send it to /dev/null