Need help to create cron job


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need help to create cron job
# 1  
Old 09-17-2013
Need help to create cron job

Dear Experts,

I want to create cronjob with the following steps:

1. go to directory /home/logs/

Code:
$cd /home/logs/

2. copy to /tmp/ the most recent file with "prefix" local_data_ and sufix ".gz"

Code:
ls -ltr
drwxr-xr-     4096            Nov 24  2009 bak
drwxr-xr-x   24096           Aug 25  2011 DIspalys
-rw-r--r-- 1 398212681    Aug 29 02:48 request_290813.xml.res.gz
-rw-r--r-- 1 960             Sep  8 00:21 dump_20130908.ack
-rw-r--r-- 1  1529614609 Sep  8 05:42 local_data_20130908..res.gz
-rw-r--r-- 1  1535919259 Sep 15 05:25 local_data_20130915.res.gz

PLZ some help to got the latest file!!!

copy the file to /tmp/

Code:
$ cp ocal_data_20130915.res.gz /tmp/

3. go to /tmp/ and gunzip the file
Code:
$gunzip local_data_20130915.res.gz

4. grep the obtained file:

Code:
$ grep -i nass  local_data_20130915.res | wc -l > /tmp/result.txt

5. delete the file local_data_20130915.res
Code:
$ rm -f local_data_20130915.res

I need that the above steps will be executed every Monday at 8 am

as example:

Code:
00 8 **1 root Script.sh

any body can help me Smilie
PLZ

Many Thanks,

Last edited by Scott; 09-17-2013 at 12:25 PM.. Reason: Code tags PLZ...
# 2  
Old 09-17-2013
What are the OS, platform and shell you use?

Why dont you write the script and submit to us, with what you cant do or giving also the error output...
# 3  
Old 09-17-2013
Hi,
thanks for reply!

I am using Linux Redhat and I'm blocked in : how to get the most recent file with the prefix "local_data_id" then copy it to another directory.
# 4  
Old 09-17-2013
Try this:

Code:
ls -ltr local_data_* | tail -n1 | awk '{print $9}' | xargs -n1 -i cp {} /tmp

# 5  
Old 09-17-2013
I was asking, but I dont, I have no RH at the moment... If all you want is a count of a grep in a .gz file, dont you have gzcat
in which case you can simply do:
Code:
gzcat local_data_20130915.res.gz|grep nass|wc -l

# 6  
Old 09-17-2013
if that works, then the complete command would be:
Code:
cd /home/logs/;gzcat $(ls -rt local_data*.gz|tail -1)|grep nass|wc -l >/tmp/result.txt

That you could put on 2-3 lines in a script and yes, use cron to sched its execution...
# 7  
Old 09-17-2013
The question has shifted from "how do I create a cronjob?" to "how do I move the latest file?". There was a very similar thread about a week ago:

Move most recent file
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

2. UNIX for Dummies Questions & Answers

Create cron job without root

Hi there, I need to create a crone job to backup certain files on my disk without root permissions. Also if I will be able to edit cronetab then I need to know how to edit it with any editor other than vim :mad: (5 Replies)
Discussion started by: aelhosiny
5 Replies

3. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

4. Shell Programming and Scripting

How to create a cron job to take an uploaded filename and move it?

OK, So complete newbie here. I would normally do this in PHP or through my FTP program script but I can't in this case (the files are not coming from me, coming from a third party FTP upload). I have an FTP server (Linux) accepting files coming in from a standard FTP program. Each file... (2 Replies)
Discussion started by: bull_frog
2 Replies

5. Shell Programming and Scripting

Im trying to create a FTP Cron Job

Hello, Im fairly new to this and am hoping for your help in moving forward. 1. I need to carry out a FTP transfer from SERVER1 to SERVER2 at 3am every morning. 2. The FTP is to work on SERVER1 3. There will be many files to transfer (96 files per day) 4. I want to delete the files... (3 Replies)
Discussion started by: nozerf
3 Replies

6. Shell Programming and Scripting

Re : How to create this cron job?

Hello All, Hope this finds you well. I am creating this shell script that will create cron jobs in crontab file. What I am provided with is the start time , intervals and # of trials. Based of Start time ( say 7:15 am ) and interval being 15 minutes, # of trial being 5 , I should create cron... (5 Replies)
Discussion started by: samshaw
5 Replies

7. Solaris

cron job starts new cron proccess

I run cron in solaris 10 zone. One cron job which syncing files to nfs mounted on container, creates after finishing another cron proccess(/usr/sbin/cron), and after 100 existing cron proccesses next cron job will not start. It's too weird for me, I'm not able to solve this problem. Theoretically... (3 Replies)
Discussion started by: ron76
3 Replies

8. Shell Programming and Scripting

create a chmod cron job help please

hi all, I'm so embarrasingly new; apologies. So here's my dilemma; files are being uploaded to the server via a php script... this is therefore assigning ownership to 'nobody' rather than the account 'user'. It's screwing with the permissions and then the owner can't ftp download images... (2 Replies)
Discussion started by: sirj
2 Replies

9. HP-UX

How to create a cron job and run in quality system

Hi Experts, I'm a SAP Basis, I have a small doubt would request you please help on this... 1. I wold like to copy files from one system to another system? as per my knowledge "we have to mount the prod filesystem on the quality box and do a copy every day thru crontab script, or do it via... (2 Replies)
Discussion started by: mahantysk
2 Replies

10. Shell Programming and Scripting

How to create cron job automatically?

How do I write a perl script to get the cron jobs? I could do a perl -e ' system "crontab -l > jobs.txt " '; Is there a better way? Then I can use perl to make changes to jobs.txt. How can I submit the changes. I suppose I could use system "crontab jobs.txt", is there a better way? ... (0 Replies)
Discussion started by: siegfried
0 Replies
Login or Register to Ask a Question