Hi i am redirecting the top command output to some file with hostname. i want to mail that through the script. Plz advice. At present i am using this script for generating the output.

#!/sbin/sh
#This script gives the output of performance of the system and diverts the output to mentioned path
#
PERF_HOME=/usr/perflog
HOSTNAME=$(hostname)
PERFLOG_LOC=/usr/perflog
top -f  $PERF_HOME/$HOSTNAME
robby6676Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Todd MummertCommented:

my top doesn't take a -f flag...

but it does take -b (batch) and -n 3 (num iterations)   flags


so something like this might work for you:

after generating the file above

mail -s "top output" user@host <$PERF_HOME/$HOSTNAME


or   w/ my flags

top -b -n 3 | mail -s "top output" user@host





0
omarfaridCommented:
you can do

#!/sbin/sh
#This script gives the output of performance of the system and diverts the output to mentioned path
#
PERF_HOME=/usr/perflog
HOSTNAME=$(hostname)
PERFLOG_LOC=/usr/perflog
top -f  $PERF_HOME/$HOSTNAME
uuencode $HOSTNAME < $PERF_HOME/$HOSTNAME | mailx -s "top resutls for $HOSTNAME" username@domain

here top output is attached to email
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
robby6676Author Commented:
hii i am executing the script . it is generating the file but in the end it is saying in mail command cannot open.. what could b the reason.

ivmhost2:/usr/perflog>>ksh -x perflog.sh
+ PERF_HOME=/usr/perflog
+ + hostname
hostname=ivmhost2
+ + %c date
perflog.sh[6]: %c:  not found
date=
+ PERFLOG_LOC=/usr/perflog
+ hostname
+ date
+ top -f /usr/perflog/ivmhost2Thu May 28 17:33:55 IST 2009.txt
+ mail -s perflogs ashutosh.jha@mtsindia.in
+ + hostname
+ date
perflog.sh[9]: /usr/perflog/ivmhost2Thu May 28 17:34:00 IST 2009.txt: cannot open
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

robby6676Author Commented:
could anybody help me ftp syntax in shell scripting .

rgds
Robby.
0
Todd MummertCommented:
does mail -s me@privacy.net   work on the command line by itself?

does 'which mail' return the path to mail?  what about mailx?    If so, perhaps give the full path to the commands in your script.   That is a good thing to do for security reasons anyway.


It's hard to script ftp or telnet without using a package called  expect.   What you can do instead if you just want to retrieve a file is use wget.    If you need to put files, there is a wput package, but it would probably need to be installed.

man wget


0
robby6676Author Commented:
just see this.. i was trying mail -s and mailx -s as well..

#!/sbin/sh
#This script gives the output of performance of the system and diverts the output to mentioned path as a .txt file
#
PERF_HOME=/usr/perflog
hostname=$(hostname)
date=$(%c date)
PERFLOG_LOC=/usr/perflog
top -f $PERF_HOME/`hostname``date`.txt
mailx -s "perflogs" ashutosh.jha@mtsindia.in <$PERF_HOME/`hostname``date`.txt
0
Todd MummertCommented:
ah...

your two calls to date are returning different values since they're called at different times

before your top command

FILE=$PERF_HOME/`hostname``date`.txt    

top -f $FILE

mailx -s "perflogs" ashutosh.jha@mtsindia.in <$FILE

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.