Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

KSH script not outputting a readable file.

Status
Not open for further replies.

hg4372

Technical User
Feb 9, 2009
43
0
0
US
I have a KSH script that is working great on Solaris 10 Sparc, however I FTP this script to a different machine running Solaris 9, and now the #.LIVE.txt output is garbage when viewing from Web Browser. The original file shows fine, so it seems to be an issue with my Tail +15. I'm so confused. Please help.

Seems to be an issue with tail.

#!/usr/bin/ksh
# echo "Enter switch: \c"
# read switch
# echo "Enter username: \c"
# read username
# echo "Enter password: \c"
# read password
switch=$1
dt=$(date +%m%d%y_%H%M)
username=user
password=password

for x in 1
do
{
echo $username
sleep 5
echo $password
sleep 15
echo "cd /var/log"
sleep 5
echo "cat system_check.log"
sleep 10
echo "cd checks"
sleep 5
echo "ls -ltr"
sleep 5
echo "exit;"

}|telnet $switch>/export/public1/index_files/team_docs/bsmchklive/$switch.txt

cp /export/public1/index_files/team_docs/bsmchklive/$switch.txt /export/home/stlonse/data/bsmchk/$switch.CHK_$dt

done

tail +15 /export/public1/index_files/team_docs/bsmchklive/1.txt > /export/public1/index_files/team_docs/bsmchklive/1.LIVE.txt

tail +15 /export/public1/index_files/team_docs/bsmchklive/2.txt > /export/public1/index_files/team_docs/bsmchklive/2.LIVE.txt

tail +15 /export/public1/index_files/team_docs/bsmchklive/3.txt > /export/public1/index_files/team_docs/bsmchklive/3.LIVE.txt

tail +15 /export/public1/index_files/team_docs/bsmchklive/4.txt > /export/public1/index_files/team_docs/bsmchklive/4.LIVE.txt

tail +15 /export/public1/index_files/team_docs/bsmchklive/5.txt > /export/public1/index_files/team_docs/bsmchklive/5.LIVE.txt

tail +15 /export/public1/index_files/team_docs/bsmchklive/6.txt > /export/public1/index_files/team_docs/bsmchklive/6.LIVE.txt
 
hg4732,

Which tail are you using?

I have the following on my Solaris 9 server.

/usr/bin/tail
/usr/xpg4/bin/tail
/usr/ucb/tail
/usr/local/bin/tail

Are you running it interactively or via cron? Do you get the same output both ways?

John
 
I have the following:

/usr/bin/tail
/usr/xpg4/bin/tail
/usr/ucb/tail

Trying to make it work interactively , however the goal will be Cron.

For some reason it is putting all the text in the new file all together. Example

First file.
BOB
GEORGE
JEFF
GREG
BILLY

Second file after tail.

BOBGEORGEJEFFGREGBILLIY

Almost like it is stripping the CR or something

When I cat or vi the file it looks fine, but from IE, Mozilla, etc.. it is garbage.
 
I presume "which tail" shows it's using /usr/bin/tail, right?

Open the file with vi and type

:set list

and make sure there aren't any special characters.

It should just look like this:

BOB$
GEORGE$
JEFF$
GREG$
BILLY$

It doesn't explain the problem, but you could try using this instead of the tail +15:

awk 'NR>14' /export/public1/index_files/team_docs/bsmchklive/1.txt > /export/public1/index_files/team_docs/bsmchklive/1.LIVE.txt

John
 
Sorry it took so long for me to get back.

The awk worked great.

Thanks for your help with this.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top