replacing first pattern using sed - sed

I have a cron job with below details
The timing section is unknown, it might be hourly or daily.
cat zyx.txt
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
0 * * * * root /usr/local/bin/log-cleaner
I have to update it on the fly using sed, so that it should run every minute .
Here is what I have tried
sed -in 's/\(.*\) \(.*\) \(.*\)/\* \* \* \* \*/1' zyx.txt
But it is removing the user and path section
cat zyx.txt
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* * * * *
Any help / suggestion using sed is much appreciated

Related

Issue with aix sed command

I am trying to uncomment "/usr/lib/sa/sa1" or "/usr/lib/sa/sa2" entries from one of the configuration file.
Below is the regex:
"^[0-9].*/usr/lib/sa/sa(1|2)"
Eg:
#0 * * * * /usr/lib/sa/sa1 1200 3 &
#5 23 * * * /usr/lib/sa/sa2 -s 0:00 -e 23:01 -i 3600 -ubcwyaqvm &
Output should be:
0 * * * * /usr/lib/sa/sa1 1200 3 &
5 23 * * * /usr/lib/sa/sa2 -s 0:00 -e 23:01 -i 3600 -ubcwyaqvm &
Tried the below "sed" command but no luck:
sed -e '/^#.*\/usr\/lib\/sa\/sa\(1\|2\)/s/^#//g' adm
Can you please let me know where am I going wrong here.
Thanks in advance!
You can use
sed '/^#.*\/usr\/lib\/sa\/sa[12]/s/^#//'
Here, no grouping construct is used, no alternation operator is used either. It is possible as the 1 and 2 are single char alternatives, and bracket expressions are supported in all versions of sed.
Also, see this online demo.

unable to use Crontab in Linux?

i use fallowing command to excute my script in every 30 min
*/30 * * * * /home/g-m-iqbal/Desktop/Auto/algo.sh
and also try this
*/30 * * * * /home/g-m-iqbal/Desktop/Auto/ && sh algo.sh
here
/home/g-m-iqbal/Desktop/Auto this the path of script

Cron expression difference between */5 and 0/5

I have a cron properties file and some of the properties contain expression like:
"* 0/5 * * * ?"
and some of them contain:
"* */5 * * * ?"
What is the difference between the two?
If I want to run every 5 minutes then which one should be used?
Thanks
PS: My project is using spring scheduler.
You can use "*/5 * * * * *" for every 5 minutes and 0 0/5 8-10 * * * for every 5 minutes between 8 o'clock and 10 o'clock
For more info read this

Better method to append to output crontabs

So i have simple shell commands to ping websites to retrieve data about said websites.
For example one of my pinging.sh looks like this:
ping -R -c 120 blar.org.cn >> pingdata.txt
ping -R -c 120 another.net >> pingdata.txt
But then my crontabs look like this:
7 * * * ./pinging.sh >> pingdata.log
The pingdata.log doesn't output. Is it best to do it through the crontab or through the script? I assumed the crontab would be better because it would cover the entire script rather than having to write it out multiple times.
You need to indicate the full path of your script in the cronjob, together with the binary running it.
For example:
7 * * * * /bin/sh /home/you/pinging.sh >> /home/you/pingdata.log
Note also you are just adding 4 parameters to the cronjob, whereas you need at least 5:
+---------------- minute (0 - 59)
| +------------- hour (0 - 23)
| | +---------- day of month (1 - 31)
| | | +------- month (1 - 12)
| | | | +---- day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed
You can test your cron syntax with Crontab guru (---> http://crontab.guru/).
First, the executable must be provided as full path in cron.
Example:
7 * * * * /bin/bash /path/to/pinging.sh
Second, create a wrapper script for pinging.sh >> pingdata.log and add that to crontab.
Third, your crontab entry is wrong. There must be 5 fields whereas your's have 4 (maybe that's a typo ?)

crontab : yesterday's date not showing up

I need a cron job to work on a file named like this:
20160307_20160308_xxx_yyy.csv
(yesterday_today_xxx_yyy.csv)
And my cron job looks like this:
53 11 * * * /path/to/python /path/to/python/script /path/to/file/$(date -d "yesterday" +"\%Y\%m\%d")_$(date +"\%Y\%m\%d")_xxx_yyy.csv >> /path/to/logfile/cron.log 2>&1
Today's date is getting calculated properly but I am unable to get yesterday's date working. The error is:
IOError: [Errno 2] No such file or directory: 'tmp/_20160308_xxx_yyy.csv'
Please help!
I found the answer to my own question.
I needed to use this to get yesterday's date:
53 11 * * * /path/to/python /path/to/python/script /path/to/file/$(date -v-1d +"\%Y\%m\%d")_$(date +"\%Y\%m\%d")_xxx_yyy.csv >> /path/to/logfile/cron.log 2>&1
Hope it helps somebody!
This version worked for me. Maybe it can be helpful for someone:
53 11 * * * /path/to/python /path/to/python/script /path/to/file/$(date --date '-1 day' +"\%Y\%m\%d")_$(date +"\%Y\%m\%d")_xxx_yyy.csv >> /path/to/logfile/cron.log 2>&1