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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Line works but not script 1

Status
Not open for further replies.

roycrom

Programmer
Aug 2, 2002
184
GB
Hi all,

I'm trying to write a script that outputs an XML file to be put on a 'service status' page. I have nearly everything in place now - I am successfully checking web servers, DNS servers, DB servers, proxy servers but the last thing I am struggling with is FTP.

I have fallen back to using telnet'ing port 21 as FTP does not have a robust return code system.

I am running this command from the command line which works perfectly:
Code:
echo ^] | telnet ftp.server 21 | grep MOTD | awk {'print $1'}
If the server responds on that port it will print MOTD and my command picks that up and outputs the number '1'. I have changed the MOTD to MTOD and the grep doesn't pick it up and outputs 0, therefore I have a valid return - either 0 or 1 which lets me know if FTP is up or not on the remote server.

However, if I try to run this from within a bash script:
Code:
#!/bin/bash
echo ^] | telnet ftp.server 21 | grep MOTD | awk {'print $1'}
then it always returns 0 as if the grep does not find anything.
Any pointers would be much appreciated.

Thanks

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
Hi

First, [tt]awk[/tt] is able to find that "MOTD" string in the input, so no need for [tt]grep[/tt] "
Code:
echo ^] | telnet ftp.server 21 | awk '/MOTD/{print $1}'
Second, your quoting style is horrible.

Third, I find [tt]netcat[/tt] much flexible than [tt]telnet[/tt], so I would try :
Code:
echo quit | netcat ftp.server 21 | awk '/MOTD/{print $1}'
Fourth, why not use an FTP client, like [tt]ftp[/tt] ?
Code:
echo quit | ftp -n -v ftp.server | awk '/MOTD/{print $1}'

Feherke.
 
Fourth, why not use an FTP client, like ftp ?
Code:
echo quit | ftp -n -v ftp.server | awk '/MOTD/{print $1}'
Perfect - thanks a lot for your quick reply.

I had started off with the ftp client but was trying to use return codes which was not going too well - I'm more than happy with the solution you suggested. Does what I need and is simple.



------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top