Need to write a shell script on AIX box which will connect to different servers using SFTP and get the file count of only 1 day older files. (purging list)
How to achieve this?
On local server we can use:
find <path> -type f -mtime +1
But how to do it in case of SFTP? Please advise. Thanks in advance.
When you say "1 day old files", do you mean files from yesterday or files that are at least 24 hours old? And are there files even older than 1 day, or just "1 day old" and current ones?
I want to display files which doesn't have today's time stamp (output of ls -ltr). Basically pending files.
So I am thinking
sftp and redirect ls -ltr to file
use awk and find out which files doesn't have todays time stamp.
How do I use awk on ls -l ? Please advise.
Ex: (ls -l)
-rw-r--r-- 1 abc dba 0 Nov 27 17:27 d
-rw-r--r-- 1 abc dba 0 Nov 27 17:27 c
-rw-r--r-- 1 abc dba 0 Nov 26 17:27 b
-rw-r--r-- 1 abc dba 0 Nov 27 17:27 a
Today's date is 27th Nov, So script should get count of files which doesn't have date 27th Nov
So here output would be 1
hi, list the files in one file and run the below command.
dat=yesterday_date (if u want I will give the full command to get the yesterday's date)
grep "$dat" $file | wc -l
Above command will give the count of previous days files.
If you have any trouble to listing the files in one file, feel free to ask me.
---------- Post updated 01-12-13 at 12:06 AM ---------- Previous update was 01-11-13 at 05:56 AM ----------
Franklin,
Follow the below steps as it is...
dat=`date -d "-1 day" | awk '{print $2, $3}'`
BINCURL=/usr/local/bin/curl ( Change curl path according to your server)
PROXYPARM = if you have proxy please put mention here.
TMPLISTFILE = File name where you want to store the sftp list output
USER & PASSWORD= Put your credentials here
CLIENT_FTP_PROTOCOL= sftp
CLIENT_FTP_SERVER= your sftp server name
PORTPARM=port number
SUBDIRPARM= Exact path in sftp server
$BINCURL -k --disable-epsv -s $PROXYPARM -o $TMPLISTFILE
-u $CLIENT_FTP_USER:$CLIENT_FTP_PASSWORD
$CLIENT_FTP_PROTOCOL://${CLIENT_FTP_SERVER}${PORTPARM}/${SUBDIRPARM} > /dev/null 2>&1
Now you can find the total sftp list in TMPLISTFILE file.
And execute the below command for yesterday's count