Error when connecting to remote server to find files with timestamp today's day


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error when connecting to remote server to find files with timestamp today's day
# 1  
Old 04-11-2017
Error when connecting to remote server to find files with timestamp today's day

I am connecting to remote server and try to check if files with timestamp as Today's day are on the directory. Below is my code
Code:
 TARFILE=${NAME}.tar
TARGZFILE=${NAME}.tar.gz
ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;
Today=`date +%Y%m%d`;
if [ `ls *${Today}* | wc -l` = 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 abnormaly"
                exit 1
        fi
        gzip transfer_dmz_start_monthly.tar'
fi

Error:

Code:
  `else' unmatched
/export/applications/ibm6000/mbsesb/sh/transfer_dmz_start_monthly.sh[74]: syntax
 error at line 75 : `fi' unexpected

Could you please help me to find the problem?

Thanks for contribution

p.s. ${DESTSERVNAME} set from configuration file
# 2  
Old 04-11-2017
once again, I'd strongly encourage using set -x when troubleshooting....
Code:
 TARFILE=${NAME}.tar
TARGZFILE=${NAME}.tar.gz
ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;
Today=`date +%Y%m%d`;
if [ `ls *${Today}* | wc -l` -eq 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 [ $? -ne 0 ]
        then
                echo "Cannot create a tar file, the terminated abnormaly"
                exit 1
        fi
        gzip transfer_dmz_start_monthly.tar
fi'

This User Gave Thanks to vgersh99 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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 TARFILE=${NAME}.tar TARGZFILE=${NAME}.tar.gz ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;... (3 Replies)
Discussion started by: digioleg54
3 Replies

2. 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

3. Shell Programming and Scripting

preserving the timestamp of a file when copied from remote server to local server using ftp

Hi, I need to copy few files from remote server to local server. I write a shell script to connect to the remote server using ftp and go to that path. Now i need to copy those files in the remote directory to my local server with the timestamp of all those files shouldnt be changed. ... (5 Replies)
Discussion started by: arunkumarmc
5 Replies

4. UNIX for Dummies Questions & Answers

Long listing of files using find command on remote server via SSH

Hi , I am trying to find some files on a remote machine using the find command. >ssh -q atukuri@remotehostname find /home/atukuri/ -name abc.txt /home/atukuri/abc.txt The above command works fine and lists the file, but if I want to do a long listing of files (ls -l) its not working . ... (2 Replies)
Discussion started by: atukuri
2 Replies

5. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

6. Ubuntu

Connecting to a remote server

Hi, I have an interesting problem. I cannot connect to a personal server I set up. What's interesting is that I can connect to it from the LAN using its non-local IP address. However, I cannot seem to connect to it from anywhere else. Here's how my server is set up: My entire home has a... (8 Replies)
Discussion started by: Altay_H
8 Replies

7. Shell Programming and Scripting

Find files older then today & display with timestamp info

Small query- I want to do some operation on all the files older then today. Before I do that operation, i want to verify if the command works properly or not. Surprisingly, the command below returns me file, which are created today - find /mrk_archive/PG/ftp/incomming/gbs/2008 -type f... (2 Replies)
Discussion started by: kedar.mehta
2 Replies

8. Shell Programming and Scripting

Connecting to remote unix server using java?

I need help writing java code that can connect to a remote unix server, and run a script on that server. I have scoured the internet, but I have been unable to find proper documentation on how this can be accomplished. Any help is appreciated thanks. (1 Reply)
Discussion started by: developncode
1 Replies

9. Shell Programming and Scripting

Find files not accessed on a remote server and delete - Help!

Hi Guys, I am currently working on a script to find all the files that have not been accessed for the past 2 years. This, i guess has been discussed n number of times in this forum. Now, my requirement is to find all the files in the remote windows server. I have it mounted in unix. I was... (1 Reply)
Discussion started by: bond_bhai
1 Replies

10. Shell Programming and Scripting

how to find today's files & send to another server?

Hi All, My script has to find todays modified( less than 24 hrs) files & send it another server using SCP. what I wrote is find . -type f -mtime -1 | xargs ls -ltr ## to find today's files, but its giving my sh_history file also, I don't require this file at all. scp... (4 Replies)
Discussion started by: zinu
4 Replies
Login or Register to Ask a Question