Help - To copy and compress files one day ago


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help - To copy and compress files one day ago
# 8  
Old 02-08-2016
Quote:
Originally Posted by JackyJohn
Dear Don,

Many thanks for your response and sorry for missing information. I have Solaris 9 running on my machine and using bourn shell.


I have used your code but got the following error.

Code:
#!/bin/ksh
SRC_DIR='/opt/TGS/traces'
DEST_DIR='/dump/old_traces'

cd "$SRC_DIR"
ls -l RtpTrcError* | grep -F "$(printf '%(%b %e)T\n' "1 day ago")" |
while read _ _ _ _ _ _ _ _ name
do	zip "$DEST_DIR/$name.zip" "$name"
done

Error output:

Code:
root@> ./backup-trc.sh
grep: illegal option -- F
Usage: grep -hblcnsviw pattern file . . .
root@>

Moderator's Comments:
Mod Comment Please use CODE tags for sample input and output as well as for code segments.
On Solaris 9 systems, you could change grep -F to /usr/xpg4/bin/grep -F or fgrep or (a little bit slower, but OK in this case) just grep, but the Korn shell on Solaris 9 systems is a 1988 version of the Korn shell and you need a 1993 version for it to recognize the time formatting options in printf.

For a one day shift, there is an alternative adjusting the TZ environment variable and using the date utility. For example, if someone was in Pakistan where the time is 5 hours ahead of Greenwich, the normal TZ setting would be something like TZ=PKT-5, to move it back one day use TZ=PKT19 as in:
Code:
fgrep "$(TZ=PKT19 date '+%b %e')"


Last edited by Don Cragun; 02-08-2016 at 11:14 AM.. Reason: Fix typos.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to copy all structure folder create last day?

HI All, please help , i got same case . i want copy folder and directory create yesterday. for sample below : drwxr-xr-x 4 apps apps 33 Nov 23 04:00 xxxxxx@gmai.com drwxr-xr-x 4 apps apps 33 Nov 23 04:00 yyyyyyy@gmail.com drwxr-xr-x 4 apps apps 33 Nov 24 04:00... (2 Replies)
Discussion started by: fajar_3t3
2 Replies

2. UNIX for Dummies Questions & Answers

Move the files between Current day & a previous day

Hi All, I have a requirement where I need to first capture the current day & move all the files from a particular directory based on a previous day. i.e move all the files from one directory to another based on current day & a previous day. Here is what I am trying, but it gives me errors.... (2 Replies)
Discussion started by: dsfreddie
2 Replies

3. Shell Programming and Scripting

script to compress files in directory that changes its name every day

Hi all I have the following script that should compress a file in a directory: # compress log files older than 2 days find /u01/easydone/DBDUMPS/*.dmp -mtime +2 -exec gzip {} \; BUT the problem is that these files that I want to compress are inside a directory with following format: ... (5 Replies)
Discussion started by: fretagi
5 Replies

4. Shell Programming and Scripting

Help - compress file one day ago

Hi All, I'm a new member of this Forum. I have need your help to handle this request. "Compress a file name not of today but of yesterday only". For example 0 mar 08:00 TEST_RPT_STATUS_M1I_CMI20120320.xls 20 mar 08:00 TEST_RPT_STATUS_M1I_CMI20120320.rep 21 mar 08:00... (6 Replies)
Discussion started by: gio123bgg
6 Replies

5. Shell Programming and Scripting

How to extract the day of the year and use that info to copy a file remotely

Hello, Thank you in advance for helping a newbie who is having great trouble with this simple task. I'm allowed to copy one file remotely each night due to bandwidth restrictions. A new file gets generated once a day, and I need to copy the previous day's file. Here is what I'd like to do:... (1 Reply)
Discussion started by: tmozdzen
1 Replies

6. UNIX for Dummies Questions & Answers

Copy Compress as one command

Hi, I need to copy and compress files in a directory in single line of command. I am able to copy and gzip files in one command but not directory. Command that I am using for copying directory is below : cp -rp /u01/app/<directory> /u01/app/backup |gzip -r /u01/app/backup/<directory> ... (10 Replies)
Discussion started by: findprakash
10 Replies

7. UNIX for Dummies Questions & Answers

Copy and compress

Is there a way to copy a file and compress it at the same time? I realize the file can be copied and then compressed, but I was wondering if it's possible to do it in a one-line command and for that matter, if it would be more efficient to perform the operation with a one-line command? Thanks. (5 Replies)
Discussion started by: here2learn
5 Replies

8. Shell Programming and Scripting

Cron to run first day of month to calculate date 3 months ago

Hi, I would like to find out how can i calculate a date which is 3 months ago. I intend to run a cron job on the 1st of every month, and calculate the month 4 months earlier from the date. For example, if today's date is 1st May 2007, i would like to return 012007( January 2007). i can get... (1 Reply)
Discussion started by: new2ss
1 Replies

9. UNIX for Advanced & Expert Users

Compress and copy a Folder

hi Buddies , How can i Compress and move a folder through UNIX completely to windows 2000 through FTP. (1 Reply)
Discussion started by: scorpiyanz
1 Replies
Login or Register to Ask a Question