Hi all,

I hope I am in the right topic. Is there anyone available to take a look at my script and tell me if something is wrong or if something needs to be improved?

Thanks in advance for your answer. It is my first script. Here is the subject:

1. Write a shell script called /tmp/shellscript.sh
2. Have the shell script gather the current memory configuration and CPU information
3. Write that data to a file called /tmp/memory
4. In the script, write out to the /tmp/users file with current-logged-in users information (you could the w command to gather this information)
5. When running the script, pass a single parameter to it which will determine how many many itterations of top to run. With that information passed to the script, run top in batch mode with the number of iterations passed to it on the command line. For example, when you type shellscript.sh 2, it will run top 2 times. Output the top data to a file called /tmp/top
6. Create a tar file of the /tmp/memory, /tmp/users, and /tmp/top files, and name the file with today's date, as in this format: tarfile-15092013.tgz. The date of the file must be notated as a VARIABLE in the script
7. The last entry in the script should have the tar file emailed to the local root user with the subject line "tarfile attached". Run the script once to generate the file.

Code:
#!/bin/sh

VARIABLE=`date +%d%m%Y`

clear
cat /proc/cpuinfo /proc/meminfo > /tmp/memory
w > /tmp/users
top - n $1 -b > /tmp/top
tar -czPf tarfile -$VARIABLE.tgz /tmp/memory /tmp/users /tmp/top

echo "File generated by script" | mutt -s "tarfile attached" -a "tarfile.$VARIABLE.tgz" root