Script for SFTP Status Checking


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for SFTP Status Checking
# 1  
Old 10-31-2012
Script for SFTP Status Checking

Greetings...

I have to construct shell script to check the SFTP status,

Define a global variable (say sftpStatus). Set it to default value "success" when you define it first time outside the script.
check the current SFTP status (say currentStatus - local variable within the script)
Code:
if (sftpStatus is success and currentStatus is failed)
   send an alert to support team
   set sftpStatus to failed
else 
if (sftpStatus is failed and currentStatus is success)
   send service restoration mail
   set sftpStatus to success

No alert is needed if both these variables are success or failed

Please Let me know script

Last edited by manju98458; 10-31-2012 at 01:21 PM.. Reason: code tags
# 2  
Old 10-31-2012
Are you running SFTP using a batch file? Please provide us more information.
# 3  
Old 11-01-2012
no it's not a batch file ,External SFTP services are running in Linux Box we have to monitor the services with shell script
# 4  
Old 11-01-2012
Ok. Looks like you want to retain the value of these 2 variables each time you run your script. I suggest storing these variable values in files. Here is a template of how you can achieve this, you can modify as per your need:-

Code:
sftpSTATUS=`cat sftpstatus.dat 2> /dev/null`

if [ -z "$sftpSTATUS" ]
then
        echo "success" > sftpstatus.dat # Setting default status for sftpSTATUS
fi

echo "#Status of SFTP service (success/failed)" > currentstatus.dat

currentSTATUS=`cat currentstatus.dat 2> /dev/null`

if [ "$sftpSTATUS" = "success" ] && [ "$currentSTATUS" = "failed" ]
then
        # send an alert to support team
        echo "failed" > sftpstatus.dat
elif [ "$sftpSTATUS" = "failed" ] && [ "$currentSTATUS" = "success" ]
then
        # send service restoration mail
        echo "success" > sftpstatus.dat
fi

I hope it helps.
This User Gave Thanks to Yoda For This Post:
# 5  
Old 11-02-2012
Is it possible to do the same script without calling the file name outside the script with golbal variable if yes, can you please provide me script with golbal variable
# 6  
Old 11-02-2012
When the script execution terminate, the value stored in the variable will be lost. This is the reason why we have to store it in a file or DB. AFAIU you want this variable value available during each execution which is why I suggested this approach.
# 7  
Old 11-07-2012
bipinajith,

Do you have any alternate solution which we can use the global variable so that the values also should be stored in the script itself with export

Please suggest and shares the scipt if you have

---------- Post updated at 07:34 AM ---------- Previous update was at 07:28 AM ----------

Last edited by manju98458; 11-08-2012 at 11:21 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking LB status.. stuck in script syntax of code

#!/bin/ksh #This script will check status of load balancer in AIX servers from hopbox #Steps to do as folows : #Login to server #netstat -ani | grep <IP> #check if the output contains either lo0 OR en0 #if the above condition matches, validation looks good #else, send an email with impacted... (7 Replies)
Discussion started by: vinil
7 Replies

2. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

3. Shell Programming and Scripting

Shell Script for continuously checking status of a another script running in background, and immedia

Hi, I want to write a script which continuously checking status of a script running in background by nohup command. And if same script is not running then immediately start the script...please help.. i am using below command to run script nohup system_traps.sh & but in some... (9 Replies)
Discussion started by: ketanraut
9 Replies

4. Shell Programming and Scripting

Checking directory status

Can I use -ctime/-mtime to verify if a particular directory has been updated or not? I don't care about number of days. I just want to perform some operations only if the folder is modified (or it's metadata is modified), i.e. some files are added to the directory. This thread has a more... (1 Reply)
Discussion started by: Pramit
1 Replies

5. Shell Programming and Scripting

checking the status of sendmail

Hi All, I like to check the status of sendmail and take the appropriate action based on success / failure etc. I have gone through one of the thread where a suggestion is made to use RC for return code Following is the code: ================================== #!/usr/bin/bash export... (0 Replies)
Discussion started by: tmanda
0 Replies

6. Shell Programming and Scripting

Checking the status of mail sent.

Hi, Is there any way to check the status of the mail sent or not.e.g mail -s "Error Message" abc@xyz.com <aaa/bbb/data.txt Can it return a status code which will confirm the delivery of mail sent?Please suggest. Thanks, Anil (1 Reply)
Discussion started by: anil029
1 Replies

7. Shell Programming and Scripting

Checking Status of PID

I'm developing a script that spawns many background processes that will be executing concurrently and need to check the exit status of each spawned process after it terminates. After starting the background process I can get the pid from $! which I can store in an associative array but how do I... (2 Replies)
Discussion started by: twk
2 Replies

8. Shell Programming and Scripting

Checking the status of the script on remote machine

Hi! I have a script, which calls another script on a remote machine using ssh. I need to check if the remote running script is succesful. If it is succesful I need to continue the for loop (run it on another machine) or break the loop. Please let me know if anyone has an idea on checking the... (3 Replies)
Discussion started by: nua7
3 Replies

9. Shell Programming and Scripting

checking exit status of a shell script

Hi, I have tried with the following code; if ;then echo "Failure." else echo "Success." fi to test the exit status of the test.ksh shell script. But whatever is the exit status of the test.ksh shell script Failure. is always printed. Please help. regards, Dipankar. (2 Replies)
Discussion started by: kdipankar
2 Replies

10. Shell Programming and Scripting

Checking Exit Status

I hope one of you smart people out there can help me with what seems like a real simple questing but I can't quite figure out. In a script I am doing a cmp on two files. I am trying to check the exit status with an if statement but can't seem to figure out the syntax. If the exit status is 1 I... (4 Replies)
Discussion started by: PrimeRibAndADew
4 Replies
Login or Register to Ask a Question