Sponsored Content
Top Forums Shell Programming and Scripting Script connect to remote server, not find files and exit only from remote server, but not from scrip Post 302996058 by digioleg54 on Tuesday 18th of April 2017 11:15:58 AM
Old 04-18-2017
Script connect to remote server, not find files and exit only from remote server, but not from scrip

I have a script, which connecting to remote server and first checks, if the files are there by timestamp. If not I want the script exit without error. Below is a code
Code:
  
 TARFILE=${NAME}.tar
TARGZFILE=${NAME}.tar.gz
ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;
Today=`date +%Y%m%d`;
files=`ls *${Today}* | wc -l`
echo "FILES ${files}">>${LOGF}
if [ ${files} = 0 ];then
        echo "We have no monthly file ${Today}. ${NAME}.sh is exiting"
        exit 0
else
        find . -ctime -1 | tar -cvf transfer_dmz_start_monthly.tar *${Today *.*;
        if [ $? != 0 ]
        then
                echo "Cannot create a tar file, the terminated abnormally"
                exit 1
        fi
        gzip transfer_dmz_start_monthly.tar
fi'
 if [ $? != 0 ]
then
        echo "Something is wrong with connection to ${DESTSERVNAME} or ${MONTH_DEST_DIR}. Please check the connecttion to ${DESTSERVNAME} or files on ${MONTH
_DEST_DIR}. If there is only *tar file, delete it.">>${LOGF}
         echo "!!!!! Alert!!!! Please check ${LOGF} and act accordingly. Please contact xxxx@xxxx.db.com. ${NAME}.sh terminated abnormaly" | mailx -r xxxx.xxxxxxxx@db.com -s "Script ${NAME}.sh failed" xxxx.xxxxxxxx@db.com
        exit 1
fi
 echo "${TARGZFILE} file was created successfuly ,starting to scp from ${DESTSERVNAME},then unzip and untar ${TARGZFILE}" >> $LOGF
echo >>${LOGF}
echo >>${LOGF}
 #scp zipped file to DTE server
/usr/bin/scp ${DESTSERVNAME}:${MONTH_DEST_DIR}/${TARGZFILE} ${LOCL_FILES_DIR}/cool_${Today}/monthly
 if [ $? != 0 ]
then
        echo "Cannot scp ${TARGZFILE} file from ${DESTSERVNAME}. Please check if all files are on ${MONTH_DEST_DIR}/monthly.">>${LOGF}
        echo "!!!!!!Alert!!!!!Please check ${LOGF} and act accordingly.Please contact xxxxx@xxxx.db.com.  ${NAME}i.sh terminated abnormaly" | mailx -r xxxx.xxxxxxxx@db.com -s "Script ${NAME}.sh failed" xxxx.xxxxxxxx@db.com
        exit 1
fi

The problem is that exit (which I put in read bold) exit only from remote server and continue run program, until scp tar file. It fails because we don't create it.
Could you please advice me to make a logic to exit from the script, if there are no files on remote server?

Thanks for contribution

---------- Post updated at 11:15 AM ---------- Previous update was at 10:25 AM ----------

I found solution.

Thanks
 

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Connect to a Remote Sybase Server Through Script.

Hi all, I am trying to connect to Remote Sybase database Server through shell script. I am operating on WindowsXP, connect to Unix(version SunOS: 5.8) The thing is i dont know how to connect to Sybase Server through my script file? Are there any manual pages which can guide me through the... (2 Replies)
Discussion started by: Aparna_k82
2 Replies

2. Shell Programming and Scripting

Connect to a Remote Sybase Server Through Script

Hi all, I am trying to connect to Remote Sybase database Server through shell script. I am operating on WindowsXP, connect to Unix(version SunOS: 5.8) The thing is i dont know how to connect to Sybase Server through my script file? Are there any manual pages which can guide me through the... (3 Replies)
Discussion started by: Aparna_k82
3 Replies

3. Shell Programming and Scripting

shell script for how to connect to a remote server by using ssh

i want to connect to a remote server through ssh. i have to also provide password within that script. after connecting to the remote server i want to do some operations like grep,cd etc can u pls help me to wite a script. Thanks (1 Reply)
Discussion started by: millan
1 Replies

4. Shell Programming and Scripting

Script to connect to a remote server and execute scripts

Hello All I need a script or set of commands which can establish a remote connection with another server and execute some scripts over there. Basically it has to establish the connection with the remote server as an user ,say 'testuser' and then execute the script 'testscript'. and return the... (5 Replies)
Discussion started by: sgbhat
5 Replies

5. Shell Programming and Scripting

Need help on how to exit a script run on a server from a remote server

hi, I am using the below line to run a script from remote server(say server A) to another server(say server B). ssh username@servername ksh script name. The issue is the script logs into server B, executes the script on server B, transfers the file to server A but does not exit from... (4 Replies)
Discussion started by: yohasini
4 Replies

6. HP-UX

Connect to remote server using sftp with password define within command/script

I am trying to connect to remote server in hp-ux, using sftp command (using sftp username@ip and password ) able to connect to remote server but, in this case sftp prompt for password and user need to manually enter it. I want sftp can read a password define in script or from file, so it can... (1 Reply)
Discussion started by: ketanraut
1 Replies

7. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

8. Shell Programming and Scripting

Shell script to find the GB files in /tmp directory in remote server

Hi, i need help on shell scripting. Main intention of the script is step 1: ssh to remote server Step 2: cd /tmp in remote server Step 3: in tmp i want to grep only files and directories which are in GB sizes All the servers list file is - tmpsrv.txt vi tmpsrv.txt ... (17 Replies)
Discussion started by: kumar85shiv
17 Replies

9. Shell Programming and Scripting

Sudo connect to a remote server and execute scripts in remote server

Hello Every one!! I am trying to write a shell script which will connect to a remote server and execute scripts which are at a certain path in the remote server. Before this I am using a sudo command to change the user. The place where I am stuck is, I am able to connect to the... (6 Replies)
Discussion started by: masubram
6 Replies

10. Shell Programming and Scripting

How to keep staying on remote server after executing a shell script with if then exit end statement?

i have a "if .. then exit end " in s shell script on remote servers. now the connection to the remote server got killed after i run this script on the remote servers. How do i run this script on remote hosts and still keep remote connections alive after executing the script. Thank you. (10 Replies)
Discussion started by: moonmonk
10 Replies
DBLINK_CONNECT_U(3)					  PostgreSQL 9.2.7 Documentation				       DBLINK_CONNECT_U(3)

NAME
dblink_connect_u - opens a persistent connection to a remote database, insecurely SYNOPSIS
dblink_connect_u(text connstr) returns text dblink_connect_u(text connname, text connstr) returns text DESCRIPTION
dblink_connect_u() is identical to dblink_connect(), except that it will allow non-superusers to connect using any authentication method. If the remote server selects an authentication method that does not involve a password, then impersonation and subsequent escalation of privileges can occur, because the session will appear to have originated from the user as which the local PostgreSQL server runs. Also, even if the remote server does demand a password, it is possible for the password to be supplied from the server environment, such as a ~/.pgpass file belonging to the server's user. This opens not only a risk of impersonation, but the possibility of exposing a password to an untrustworthy remote server. Therefore, dblink_connect_u() is initially installed with all privileges revoked from PUBLIC, making it un-callable except by superusers. In some situations it may be appropriate to grant EXECUTE permission for dblink_connect_u() to specific users who are considered trustworthy, but this should be done with care. It is also recommended that any ~/.pgpass file belonging to the server's user not contain any records specifying a wildcard host name. For further details see dblink_connect(). PostgreSQL 9.2.7 2014-02-17 DBLINK_CONNECT_U(3)
All times are GMT -4. The time now is 06:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy