1753604 Members
5878 Online
108797 Solutions
New Discussion юеВ

script help urgent

 
CHEN WAI CHUAN
Occasional Contributor

script help urgent

i want to write a script to output multiple commands output to a file eg . list dmesg,ioscan & bdf output to a.out file.
4 REPLIES 4
John Poff
Honored Contributor

Re: script help urgent

Hello,

To get the output of multiple commands into one output file, you just need to specify the redirection to append to the file. Try something like this:

dmesg >file.txt
ioscan -fn >>file.txt
bdf >>file.txt

The first redirection just uses one greater than symbol '>' which will create the file and send standard output to it. The next two redirections use two greater than symbols '>>' which append to the file. If you want to keep writing information to the same file without clearing it at the start you can make the first command use '>>' also.

I hope this helps you. If not, post another question and we'll try something else.

JP

Rob Smith
Respected Contributor

Re: script help urgent

Hi, try this:

#!/usr/bin/sh

SYSTEM=`hostname`
STALE=`vgdisplay -v | grep stale | wc -l`

print "$SYSTEM"

print `date`

if [ $STALE = 0 ];then
echo "No Stale Mirrors on $SYSTEM"
else
echo "The Following Mirrors are Stale on $SYSTEM: "
vgdisplay -v | egrep -e "LV Name" -e "stale"
fi

echo ""
UNAVAIL=`vgdisplay -v | grep unavail | wc -l`

if [ $UNAVAIL = 0 ];then
echo "No Unavailable Drives on $SYSTEM"
else
echo "The Following Drives are Unavailable on $SYSTEM: "
vgdisplay -v | egrep -e "Name" -e "unavail"
fi

echo ""
echo "Uptime Output"
uptime

echo ""
echo "Who -br Output"
who -br

echo ""
echo "Output of bdf -l"
bdf -l

echo ""
echo "Last 10 Lines of Dmesg"
echo ""
dmesg | tail -10

echo ""
echo "Last 25 Lines of /var/adm/syslog/syslog.log"
echo ""
tail -25 /var/adm/syslog/syslog.log

echo ""
echo "Ioscan Output"
ioscan -kf

When you run it you can pipe it to a file or e-mail it to yourself etc. I hope this helps.

Rob

Learn the rules so you can break them properly.
Michael Tully
Honored Contributor

Re: script help urgent

Hi,

If you wish to run something simple you
just use the script program:

# script /tmp/output
# dmesg
# ioscan -fn
# bdf
# vgdisplay -v

etc etc...
The output of all of these will go to
/tmp/output

To finish use Cntl D

HTH
Michael
Anyone for a Mutiny ?
Andreas Voss
Honored Contributor

Re: script help urgent

Hi,

you can redirect all output within a script when adding a line such as:

exec >file.log

at the top of the script. All following command will put their output to the file.log

Using

exec >file.log 2>&1

will also redirect standard error of all following commands to the file.

Regards