Rename inside the crontab file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rename inside the crontab file
# 1  
Old 03-01-2018
Rename inside the crontab file

Hi Team,

i have below file is my crontab,

00 * * * * /home/****/ >> /$$$$/#####/status.txt
00 * * * * /home/$$$$$/ >> /$$$$/#####/status.txt

i want to replace/rename the file _20480 with 40960

I have tried with below command but there is no change happening in
crontab file.

crontab -l -u splunk | sed 's/*_20480/40960/' | crontab -

please suggest

Last edited by jim mcnamara; 03-01-2018 at 05:06 PM.. Reason: missed adding the command
# 2  
Old 03-01-2018
Try something like this:
# crontab -l -u hergp
0 * * * * /home/hergp/
# EDITOR="sed -i s/hello/world/" crontab -e -u hergp
crontab: installing new crontab
# crontab -l -u hergp
0 * * * * /home/hergp/

# 3  
Old 03-01-2018
First off, it is good that you are trying to use the crontab command to alter the file.

However, I get the idea that you have lots of redundant lines in your crontab file. Otherwise you would not bother with a script like this.

Correct me if I'm wrong, but otherwise you should simply use the crontab without pipes and sed. Just a single one line entry pointing to the shell script. Let it do all of checking testing and renaming. You can safely use most text tools on the script - you cannot do that with crontab files necessarily.

If I'm correct you should copy all of that crud out of crontab and place it in a single larger shell script where you won't have problems like the one one you have now. crontab is a special kind of file and it is easy to mess it up and get lots of errors generated into many email messages, for example.

Do not rename the crontab file.
# 4  
Old 03-01-2018
The preferred way would be to use the crontab command to delete the job and then the crontab command to enter the new job.

You should not edit the crontab directly because changes will not be seen by the cron daemon (for a while). When the system boots cron daemon starts, reads all the crontabs into memory along with their last modified date/time, and then runs. Periodically, (typically once every 24 hours) cron will check by comparing the date/time of crontabs that it has the latest versions. If a crontab has changed it will then notice it and reload that table. Until then no changes will take place.

If you are desparate you could (but not recommended) edit the crontab file directly and then get someone with root access to stop/start or restart the cron daemon so that the change(s) are read in. How you restart the cron daemon will depend on your OS which you do not state.

Hope that helps.

Last edited by hicksd8; 03-02-2018 at 05:28 AM.. Reason: Typo correction
# 5  
Old 03-02-2018
A leading * requires a leading literal *
crontab -l | sed 's/_20480/40960/' | crontab -

The idea with a leading character and a trailing character is good, it prevents a partial match in the wrong line. The matching boarder charaters must be re-added in the substitution string
crontab -l | sed 's#/_20480\.#/40960.#' | crontab -

A compromise is a word match; the anchors \< and \> match a word boundary but not a character, are not to be re-added in the substitution string
crontab -l | sed 's/\<_20480\>/40960/' | crontab -

# 6  
Old 03-02-2018
Hi Everyone,

Thanks for the update everyone, i had tried above commands , it did not work for me. I wanted to rename file name, putting in more details so that i can get my answer for my question:

i have below line in crontab

00 * * * * /home/@@@@/ >> /export/####/$$$$$/ulimit_nofile_status.txt

00 * * * * /home/@@@@/ >> /export/####/%%%%/ulimit_nproc_status.txt

i want to change the file name ( and to ( and these are file names.

I want to rename 20480 to 40960

Once again thanks team update, waiting for reply once again on the updated post

Last edited by Scott; 03-02-2018 at 01:50 PM.. Reason: Please use code tags. Removed poll from thread.
# 7  
Old 03-04-2018
try what @hergp suggested with re sed;

sed -r 's/(ulimit_n\w+?_status_)\'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to copy file 3 times and rename based on another file

In the below bash I am trying to copy the only text file (always only one) in /home/cmccabe/Desktop/list/QC/metrics.txt and rename each of the 3 text files according to /home/cmccabe/Desktop/test/list.txt using lines 3, 4 ,5. This format (that is list.txt) is always 5 lines. Thank you :). ... (12 Replies)
Discussion started by: cmccabe
12 Replies

2. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. UNIX for Dummies Questions & Answers

awk - Rename output file, after processing, same as input file

I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this? ... (12 Replies)
Discussion started by: High-T
12 Replies

4. Shell Programming and Scripting

RMAN commands inside crontab shell script

Hello I'm trying to write simple script to delete archive logs for RMAN, unfortunately it's not working, I tried two way to do that: #!/bin/ksh echo "Start ....." rman target=/ << EOF RUN { delete force noprompt archivelog until time 'sysdate-10'; } EXIT; EOF echo "END ..." echo... (6 Replies)
Discussion started by: samer.odeh
6 Replies

5. UNIX for Dummies Questions & Answers

look for specific values in a file and rename file with value found

Hi, i have a file with some data ..look for some specific value in the file and if found that value rename the file with the value found in the file.. ex.. File.txt 1236 43715825601ANDERSSON, 1236 437158256031963040120060901200609010000000 1236 43715825604123 MCCL AVE UPPER 1236 ... (11 Replies)
Discussion started by: dssyadav
11 Replies

6. Shell Programming and Scripting

Rename files that are inside zip file

Hello to all, I have a zip file with any name like, within the zip file there are more than 30 files with different extensions in the following format. FileName_BMN_ROSJ.txt FileName_THEUS.jpg . . . FileName_KWPWP.shx I would like to unzip the file and rename each file... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

7. Shell Programming and Scripting

Rename contents inside multiple files

Hi, I have 100 files in a directory. Each file have the following format >CtbRe01234 fdfjdhfkdfkd >CtL2B0456 gjfgfkgjfkgjfk >CmdrE05768 fghdjskksllfkLike this I have many files in the directory. What I want is; rename the header content in each file such that the above file... (6 Replies)
Discussion started by: Lucky Ali
6 Replies

8. Shell Programming and Scripting

A script that will move a file to a directory with the same name and then rename that file

Hello all. I am new to this forum (and somewhat new to UNIX / LINUX - I started using ubuntu 1 year ago).:b: I have the following problem that I have not been able to figure out how to take care of and I was wondering if anyone could help me out.:confused: I have all of my music stored in... (7 Replies)
Discussion started by: marcozd
7 Replies

9. UNIX for Dummies Questions & Answers

Rename file based on first 3 characters of data in file

I'm looking to determine if I can use a grep command to read file and rename the file based on the first 3 characters of the data in the file. An example is: Read FileA If the first 3 positions of the data in the file are "ITP", then rename the file as FileA_ITP, else if the first 3... (3 Replies)
Discussion started by: jchappel
3 Replies

10. UNIX for Dummies Questions & Answers

Help with multiple file rename - change case of part of file name

Hi there, I hope someone can help me with this problem : I have a directory (/var/www/file/imgprofil) which contains about 10000 JPG files. They have a naming convention thus : prefix-date-key-suffix.jpg they all have the prefix p-20050608- then AAAA is a 4 letter code the suffix is... (7 Replies)
Discussion started by: steve7
7 Replies
Login or Register to Ask a Question

Featured Tech Videos