Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Every morning, I SSH into a particular server. I check disk space, size of a few directories, and the contents of some specific directories.

All of this involves a lot of typing and recall (of directory locations) when I am not at my most awake.

Is there a smarter way of doing this... some kind of script that takes out some of the manual typing that I do every morning?

share|improve this question
*nix is all about automation like this. ;) So sure, of course it's possible. A simple shell script is a start. – Keith Jan 24 '13 at 7:05

You could probably do the majority of that from a bash script, yes. And get it to run every day by putting it in cron.daily, or your distro's equivalent.

Conceptually, you can call the same commands from the script as you do manually, but you'll probably want to redirect the output to append a temporary file, and then sendmail the contents of that file to yourself once done so you can just read the summary.

share|improve this answer
interesting idea – MedicineMan Jan 23 '13 at 16:57

After one of your daily sessions, just pipe the output of history | cut -c 8- to a file and then clean it up.

history | cut -c 8- >

You'll want to add redirects to append any output from each individual command into a file and then and then add a line to email the file to yourself. Then simply add the script you created to cron.daily after testing it.


df -h
cd /var/log
grep ERROR *.log


df -h >> /tmp/$$.log
cd /var/log >> /tmp/$$.log
grep ERROR *.log >> /tmp/$$.log
mail -s "Daily Status" << $$.log
rm $$.log

If you are feeling particularly lazy (one of the virtues of a good programmer ;-) add some processing to determine if action is needed. i.e. If free space is less than 90% alert you immediately or mark the email urgent.

share|improve this answer

Sure, you can write a shell script and save it on the remote server to automate these kind of work. Check out some bash scripting tutorials with Google. Then you can just ssh into the server and run the script.

share|improve this answer
Alternatively: ssh user@remoteMachine 'bash -s' < (Which will run your local shell script on the remote machine, without a need to store the script on the remote server.) – tibkov Jan 23 '13 at 17:01
could you elaborate on this idea? it's very interesting – MedicineMan Jan 23 '13 at 17:08
Sure. If you read "man ssh", you'll see that ssh takes a [command] parameter. Which means that the [command] will be running on the remote system instead of the local machine. Now the command will be 'bash -s' which means the bash shell will interpret your local script, named "". This means that your local script's content will be the input for the remote bash shell. – tibkov Jan 23 '13 at 17:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .