Hi all, posting my first time, hope not breaking posting rules with it, if yes, let me know.
I'm trying to build a script to check a file in an sftp server through a remote server.
The intention is to check the file in a sftp host, and if the file is found or not, it should send an email.
At certain point if the file is not available, we must take actions and call the provider to provide the file ASAP.
host where check is located -> remote host check -> sftp host
The following script was modified from another script I found here and tried to adapt for what I need but it is not working.
when I run it, it stays running and no email is sent to me.
Code:
#!/bin/bash
icdata=data
icinp=input
ictmp=/tmp
iclog=log
key="keys/key"
file="FILE_${date}_NAME"
date=$(date +%Y%m%d)
logname="FILE_${date}_NAME.log"
file="FILE_${date}_NAME"
logdate=$(date +%Y%m%d%H%M%S);
ssh_args=( -o "StrictHostKeyChecking=no" -qni "$key" user@host )
flag="N"
#REMOVING LOG FILES OLDER THAN 30 DAYS
find $iclog -type f -name "FILE_*_NAME.log" -follow -mtime +30 -exec rm {} \; -print
#----Log Errors in Log File---------#
inf_log()
{
echo "INFO: $@" >> $iclog/$logname
}
err()
{
echo "No $@" >> $iclog/$logname
exit 1
}
#SFTP CHECK
echo Log BEGIN For $logdate>$iclog/$logname
while [ "$flag" != "Y" ]
do
ssh -T "${ssh_args[@]}"
sftp -oPort=6022 SFTP_USER@10.11.22.33 << EOF
ls -la $file
bye
EOF
if [[ -f $file ]]; then
inf_log "File is available on SFTP for tidal job to retrieve........."
ssh -T "${ssh_args[@]}"
sftp -b - -oPort=6022 SFTP_USER@10.11.22.33 <<EOF >$iclog/$logname
ls -la $file
bye
EOF
flag='Y'
else
sleep 300
fi
done
#-------Mail SFTP status----------------------------#
grep -q '$file' $comlog/$lognm
if [ $? -eq 0 ]; then
inf_log "File is available!"
echo "File available - No Actions needed\n"|mailx -s "FILE_${date}_NAME File check Success " me@duh.com
else
echo "File not yet available - Please call PROVIDER\n"|mailx -s "FILE_${date}_NAME File check Failed " me@duh.com
err " File is not Found!!! - Please call PROVIDER ASAP"
exit 1
fi
Any suggestion or correction would be appreciated.
Thank you
Last edited by MrShinyPants; 05-06-2019 at 11:22 AM..
Looks like $file doesn't exist and never is created, so if's then branch is never executed, flag isn't set to "Y", and the while loop's exit condition is not met.
Proper indentation helps you and others read and understand your code. btw.
So i was testing the script with minor corrections but it still fails.
I execute it and stays running doing nothing.
I check the log file and it shows that log file is beginning.
Geeks,
Could you please help me out in my script and identify the missing piece. I need to check/get the exit status of a remote command executed on remote host through script and send out an email when process/processes is/are not running on any/all server(s).
Here's the complete... (5 Replies)
Hi,
Given addresses of 2 remote machines, using a shell script is it possible to
get the state of running processes in "src"
stop all the processes in "src"
exit out of "src"
ssh into "dest"
resume the state of executing processes captured in step 1 in "dest"
Assumption:
"src" is... (3 Replies)
I am able to connect to a remote host using the legacy IP and port 2222.
Today the remote has a new IP I am unable to connect.
How to check if the remote host is blocking or if its my server is unable to connect.
Err Msg : telnet: Unable to connect to remote host: Connection refused
Err... (5 Replies)
Hi all,
I am a beginner to shell script.Can any one please help me on the below requirement
I need to check whether the file (called 3Com_Files_Delivered.txt) exists on the remote mechaine or not? if so i need to copy all the files from there to my local mechaine.Especially i am... (7 Replies)
Hi,
My script needs to check whether the remote host is up or not.
If it is up i need to start few servers in that host or else just a notification should be sent that the remote host is down?
Could someone help me out in this?
Regards
Arun (4 Replies)
I do a ssh to remote host(A1) from local host(L1). I then ssh to another remote(A2) from A1.
When I do a who -m from A2, I see the "connected from" as "A1".
=> who -m
userid pts/2 2010-03-27 08:47 (A1)
I want to identify who is the local host who initiated the connection to... (3 Replies)
Gurus/Experts
We have a centralized UNIX/Solaris server from where we can actually ssh to all other UNIX/Solaris servers...I need to write a script that reside on this centerlized server and do FileSystem monitoring (basically run df -h or -k) of other remote servers and then send an email to me... (6 Replies)
I am using KSH and I need to check whether the remote host has been configured with ssh public key. Is there any way we can check inside a script? (6 Replies)