LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   FTP Script (http://www.linuxquestions.org/questions/linux-newbie-8/ftp-script-4175436758/)

manju98458 11-12-2012 07:15 AM

FTP Script
 
Greetings,

I am trying to create SFTP script to test the SFTP connectivity



issue is that I cannt able to satisfy both if and elif condition

Suggest me where iam missing in the script.

michaelk 11-12-2012 10:06 AM

Welcome to LinuxQuestions.

Just some observations. Is your server configured for public/private keys? The -b option is for non interactive commands so it does not appear to be used correctly. What is the contents of /SFTP/currentstatus.dat? And sftpSTATUS is never updated with the latest status.

To prove sftp functionality are you trying to send or receive a file from the server?

manju98458 11-12-2012 10:24 AM

SFTP is configured for Public key we are accessing the external SFTP server from our linx boxes.

yes that's true Sftp STATUS never updated.

We just connect to SFTP and we are not receiving any file from the server

unSpawn 11-12-2012 10:26 AM

Quote:

Originally Posted by manju98458 (Post 4827547)
Suggest me where iam missing in the script.

- Using string comparison where exit value should do:
Code:

echo quit > /tmp/sftpcmds.$$
sftp -o ConnectTimeout=3s -q -b /tmp/sftpcmds.$$ user@host >/dev/null 2>&1
case $? in
 0) echo OK;;
 *) echo "Returned: $?;;
esac

- Using odd paths like "/SFTP/" (see the FHS), dumping files in the CWD and not using mktemp ('man mktemp' for more),
- Using fixed values instead of getopts ('help getopts') and user input ('help read'),
- Probably should be using FUSE SSHFS or AutoSSH,
- Not business-like text but using unnecessary text amelioration like "###" and "---" lines,
- Duplicate echo commands,
- No timeouts / retesting: your "Dear Team," is not going to like you sending emails often.
*Search LQ for "Bash scripting guides".

manju98458 11-12-2012 10:35 AM

Also I am thinking to use export , is it possible to store the sftpstatus output within the script to avoid the /tmp usage

manju98458 11-12-2012 09:39 PM

Script for SFTP Status checking
 
Looking for a Script to check SFTP status with EXPORT to satisfy both

the below conditions

schneidz 11-12-2012 10:37 PM

not sure i understand ?:
Quote:

Originally Posted by manju98458 (Post 4828010)
Looking for a Script to check SFTP status with EXPORT to satisfy both

the below conditions

Code:

if [[ "$sftpSTATUS" = "success" ] && [ "$currentSTATUS" = "failed" ]]
then
 do something

elif [[ "$sftpSTATUS" = "failed" ] && [ "$currentSTATUS" = "success" ]]
then
 do something else
fi

Please let me know if any scripts


manju98458 11-12-2012 11:59 PM

We have to monitor the SFTP server connectivity. Everday we have to monitor whether the connectiy was succesfull or not. if it's successul or failed it has send alert message for failed condition and also for the restoration of the services

schneidz 11-13-2012 07:59 AM

the variable $? contains the exit status of the previous command.
Code:

scp user@server.net
if [ $? -eq 0 ]
then
 mail -s "success" user@server.net
else
 mail -s "failure" user@server.net
fi


manju98458 11-14-2012 08:50 AM

I have written script some how I was not succesfull. Please look into it and correct me if my coding is wrong to execute

unSpawn 11-14-2012 08:57 AM

Change
Code:

#!/bin/bash
to read
Code:

#!/bin/bash -vxe
then run script again and pipe stdin + stderr to a file through 'tee':
Code:

/path/to/script 2>&1 | tee /path/to/log.txt
then read "/path/to/log.txt" for clues. If you don't get it post the output using [code]vBB code tags[/code].

schneidz 11-14-2012 09:07 AM

i have a general suggestion that isnt specific to your error but wouldnt it much simpler to use scp since this is automated ?

even mounting thru sshfs would be easier.

schneidz 11-14-2012 09:12 AM

Quote:

Originally Posted by unSpawn (Post 4829220)
Change
Code:

#!/bin/bash
to read
Code:

#!/bin/bash -vxe
then run script again and pipe stdin + stderr to a file through 'tee':
Code:

/path/to/script 2>&1 | tee /path/to/log.txt
then read "/path/to/log.txt" for clues. If you don't get it post the output using [code]vBB code tags[/code].

to add to the good advice above, i think that echo is the best debugging tool.

i usually add lines like echo enter if / echo var = $var...
and then comment them out later.


All times are GMT -5. The time now is 02:38 AM.