More Bash Scripts

2012-08-28

Well I'm back after my week of doing nothing (other than playing CS:GO and watching Farscape again).

Here are some more random Bash scripts that do some mildly useful things.

A simple script to determine if a process is running or not. Useful in conjunction with other scripts (such as an auto restart script etc). Has verbose output to tell you in plain English that the process is running or not; feel free to remove that.

 
#!/bin/bash process=$1 check=`ps xco command | egrep -c "^$process$"` if [ $check -gt 0 ]; then echo "$process is running" running=1 else echo "$process is not running" running=0 fi
This is just something I use when moving files off my camera to my desktop -- it converts all filenames to lowercase. You can use ls -a in the if statement if you wanted all hidden files and folders as well.
#!/bin/bash for org in $(ls); do new=$(echo $org | awk '{print tolower($0)}') mv -v $org $new done
I didn't get round to doing much else in the way of scripting / programming, so that's all!