Sftp - 1 day older files count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sftp - 1 day older files count
# 1  
Old 11-21-2012
IBM 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:
Code:
find <path> -type f -mtime +1

But how to do it in case of SFTP? Please advise. Thanks in advance.

Last edited by Franklin52; 11-21-2012 at 07:13 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 11-21-2012
Can you use ssh to log into the servers or are those sftp-only users?
# 3  
Old 11-22-2012
IBM

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:
Code:
-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.

Last edited by Scott; 11-27-2012 at 08:03 AM.. Reason: Code tags
# 4  
Old 11-22-2012
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?
# 5  
Old 11-27-2012
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)
Code:
-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

Last edited by Scott; 11-27-2012 at 08:03 AM.. Reason: Code tags
# 6  
Old 11-27-2012
First write the output of sftp into a file

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

The output file looks like

Code:
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.
# 7  
Old 01-11-2013
Quote:
Originally Posted by hergp
Can you use ssh to log into the servers or are those sftp-only users?
How can I get the list of D-1 (date -1 ) files using ssh ? any idea??
thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Delete 5 days older files from sftp

As one of our requirement was to connect to remote Linux server through SFTP connection and delete some files which are older than 7 days. I used the below piece of code for that, SFTP_CONNECTION=`sftp user_id@host ... cd DESIRED_DIR; find /path/to/files* -mtime +5 -exec rm -rf {} \; bye... (2 Replies)
Discussion started by: ATWC
2 Replies

2. Shell Programming and Scripting

Delete 5 days older files from sftp

As one of our requirement was to connect to remote Linux server through SFTP connection and delete some files which are older than 7 days. I used the below piece of code for that, SFTP_CONNECTION=`sftp user_id@host ... cd DESIRED_DIR; find /path/to/files* -mtime +5 -exec rm -rf {} \;... (1 Reply)
Discussion started by: ATWC
1 Replies

3. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

4. Shell Programming and Scripting

Grep files older than 1 day

I thought that this would work for grep'ing files older than 1 day. ps -o etime,pid,user,args -e|awk '/^+-/'|sort -t- -n -k 1,1 |grep qdaemon |grep /usr/bin/ksh But, it is not grep'ing any of files (i.e. below) older than 1 day. d_prod 33757970 61999560 0 Oct 27 - 0:00... (8 Replies)
Discussion started by: Daniel Gate
8 Replies

5. Shell Programming and Scripting

Find processes older than 1 day

// AIX 6.1 I need to extract PIDs of ps -ef |grep /usr/lib/lpd/pio | awk '{print $2}' ps -ef |grep qdaemon |grep /usr/bin/ksh | awk '{print $2}' that are older than 1 day. I know find . -type f -mtime +1, but it doesn't work for PIDs. Please let me know how to get the PIDs older than... (1 Reply)
Discussion started by: Daniel Gate
1 Replies

6. Shell Programming and Scripting

How archive the older than 30 day files to another unix server

I need to archive the older than 30 day file to another uinx server.I have wrote the below uinx script. for LOOK_DIR in /TempFiles do for FILE in `find ${LOOK_DIR} -mtime -30 -exec ls {} \;` do echo ${FILE} >> file_list ## This file will have the list of files copied and... (12 Replies)
Discussion started by: murari83.ds
12 Replies

7. Shell Programming and Scripting

Command to Count the files which is Older than 3 months?

Hi Gurus the count of files in a particular Directory... ls -lrth | grep -c ^- can any one share the command to Count the files which is Older than 3 months So please help me out in this Thanks in Advance (2 Replies)
Discussion started by: SeenuGuddu
2 Replies

8. Shell Programming and Scripting

Find the number of files older than 1 day from a dir

Hello All, I need to write a script/command which can find out the number of .csv files residing in a directory older than 1 day. The output should come with datewise (means for each date how many files are there). I've this command, but this command gives the total number of files. It's... (10 Replies)
Discussion started by: NARESH1302
10 Replies

9. Shell Programming and Scripting

Deleting / finding files older than X days missess a day

Hi When trying to find and delete files which are, say, 1 day, the find command misses a day. Please refer the following example. xxxd$ find . -type f -ctime +1 -exec ls -ltr {} \; total 64 -rw-rw-r-- 1 oracle xxxd 81 Apr 30 11:25 ./ful_cfg_tmp_20080429_7.dat -rw-rw-r-- 1... (4 Replies)
Discussion started by: guruparan18
4 Replies

10. Shell Programming and Scripting

find files older than 30mins,count and send mail

Hi all, I wrote this script to find files older than time parameter, count the number of files, and send an email to me that some files are in a particular folder. For the particular path, the script should wait delay parameter before running again. For example, assuming the input file looks... (4 Replies)
Discussion started by: kayarsenal
4 Replies
Login or Register to Ask a Question