Sftp - 1 day older files count

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.

Can you use ssh to log into the servers or are those sftp-only users?

No, I can only sftp to the server.

Can I get the list from ls -ltr and use awk to check the time stamp?

eg:

-rw-r--r--   1 abc    users            0 Nov 22 12:37 a.txt
-rw-r--r--   1 abc    users            0 Nov 22 12:37 b.txt
-rw-r--r--   1 abc    users            0 Nov 22 12:37 c.txt

How do I use awk here to get file count which doesn't have today's date stamp.
Please advise. Thanks.

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

  1. sftp and redirect ls -ltr to file
  2. 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

First write the output of sftp into a file

sftp user@hostname <<EOF >output
    ls -l /your/dir
EOF

The output file looks like

sftp>   ls -lt /var/tmp
drwx------    3 hergp    admin        4096 Nov 16 09:00 file1
drwx------    2 root     root         4096 Nov 14 09:14 file2

Now use awk on output to get the information you need.

How can I get the list of D-1 (date -1 ) files using ssh ? any idea??
thanks!

With ssh you can use

ssh user@hostname find <path> -type f -mtime +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

grep "$dat" $TMPLISTFILE | wc -l

Hope it is useful to you.

Hi,

I used "scp" on oracle linux 5.

Can you try this

find . -name "*" -mtime +1 -exec scp <may be u use port like -P portnumber> "{}" <remote_user>@<remote_host>:<directory>";"

for example

find . -name "*" -mtime +1 -exec scp -P 34000 "{}" remote_user@remote_system:/home/remote_user/ ";"