Quote:
Originally Posted by
davidfrank
Thank you for your reply.
I am a beginner in Unix. Can you give some idea as to how I would write these codes. Is there any special command to log these information?
Thanks again.
You can always use
$ echo "Script $0 started @ `date` >> $yourlogfile"
(note that you can modify the date format, to learn more about this try `man date`)
You can grep top 900 or ps -ef for your process (pid of current process is always $$). Note if you grep with $$ you will get first child process(es) out aswell. You can also grep for $0 (program itself), but if running multible times this is not certain.
for exit status you will use $? after a commandline (for instance "ls -l *.txt 2&1>/dev/null";echo $?) --- this means if files was found exit status of ls is 0 (0 is always the good exitstatus), if its greater than 0 it means either ls was flagged bad or it returned no rows.
You will then use $? in an if like "pexitcode=$?;if [ $pexitcode -gt 0 ]; then echo "$0 went bad, exiting with status $pexitcode";fi
(its always a good idea to set $? of a commandline right after, so that you will be able to use it later on
You can always exit your program, with an exitcode/status, note that no code after an exit will be run. You can choose your own exit codes as you wish, dont know if unix core has a limit, but somewhat all you need is less than a hundred...
hope this helps