Schedule crontab job for last sunday in the month [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
We want to extend our backup system to include a monthly end backup. It will be performed the last Sunday in the month but code below is so that I can see it works today on a smaller scale.
Started with (which works)
0 12 * * 0 sudo tar -cpzf /media/BackupDisk/wwwJUNEbackup.tar.gz /var/www
Have trawled the internet and come up with this code, tested in script file
if [ $(date +%d -d '+7 days') -le '8' ] ; then
echo "Yes"
else
echo "No"
fi
(For reference this says - if today's date + 7 days is less then or equal to 8 then YES else NO)
But when I try to include into the Sudo's crontrab
26 17 * 6 5 [ $(date +%d -d '+7 days') -lt '8' ] && sudo tar -cpzf /media/BackupDisk/wwwJUNEbackup.tar.gz /var/www
I get a nothing.
What am I doing wrong?

Create trivial script last_weekday_in_month.sh and use it in your crontab entry.
You use syntax far beyond basic shell => IMHO it is better to move it to trivial script with specific shell enforced via #!/...
12 * * 0 /path/last_weekday_in.month.sh && sudo tar -cpzf /media/BackupDisk/wwwJUNEbackup.tar.gz /var/www
last_weekday_in.month.sh
#!/bin/bash
if [ $(date +%d -d '+7 days') -lt '8' ] ; then
exit 0
else
exit 1
fi

Related

How to kill certain process running more than 36 hours and containing certain phrasse in its command? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
on the Linux (CentOS 6), i want to kill process containing "pkgacc" in its command (so no exact command but just partial match) if it is running more than 36 hours.
There is related question: How do you kill all Linux processes that are older than a certain age? but any of the solutions provided do not work for me.
when executing:
if [[ "$(uname)" = "Linux" ]];then killall --older-than 1h someprocessname;fi
It just return killall usage page on how to use killall, in its manual page there is no mention about "--older-than" switch.
It is infinitely easier to invoke a program in a wrapper like timeout from GNU coreutils than to go hunting for them after the fact. In particular because timeout owns its process, there is no ambiguity that it kills the right process. Thus
timeout 36h pkgaccess --pkg_option --another_option package_name
where I made up the names and options for the pkgaccess command since you didn't give them. This process will run no longer than 36 hours.
I think you could do something like
ps -eo pid,cmd,etime
then you could parse the output with grep searching for you process,
something like that:
ps -eo pid,cmd,etime | grep pkgacc
you will have some output with one or more result, the last column from the output must be the time of running process, so one more little bash effort
and you could check if the time is greater than 36 hours.
#!/bin/bash
FOO=$(ps -eo pid,cmd,etime | grep -m 1 pkgacc | awk '{ print $1" "$3 }'| sed -e 's/\://g')
IFS=' ' read -r -a array <<< "$FOO"
if [ "${array[1]}" -gt "360000" ]; then
echo "kill the process: ${array[0]}"
else
echo "process was not found or time less than 36 hours"
fi
I think that could solve part of your problem,
see that I do not explicit kill the process but just indicate
what it is. You could improve the idea from that.

Error mounting in fstab Ubuntu [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I'm working on a bash class project which needs me to create 2 partitions in Ubuntu and make them be automatically mounted each time the systems boots with fstab.
I got the following file which creates (I think correctly) the 2 partitions needed and adds them to the fstab file.
#!/bin/bash
#SVN Partition
(echo n; echo p; echo ; echo ; echo +20G; echo w;) | sudo fdisk /dev/sdb
#WEB Partition
(echo n; echo p; echo ; echo ; echo +5G; echo w;) | sudo fdisk /dev/sdb
sudo su -c "echo '/dev/sdb1 /svn ext4 rw,user,auto,utf8 0 0' >> /etc/fstab"
sudo su -c "echo '/dev/sdb2 /web ext4 rw,user,auto,exec,utf8 0 0' >> /etc/fstab"
When I reboot the system an error appears telling me the automatic mounting for /web and /svn failed.
Does anyone have a clue on what is happening? Thanks in advance.
You haven't formatted the filesystems...
Execute these before reboot.
sudo mkfs.ext4 /dev/sdb1
sudo mkfs.ext4 /dev/sdb2

How do I schedule a timed reboot of my server in seconds? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I’m using bash shell on Linux …
$ uname -a
Linux sandbox.mydomain.com 3.4.76-65.111.amzn1.x86_64 #1 SMP Tue Jan 14 21:06:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
although it would be nice if I could come up with a solution in any bash supported environment. My question is, in my script I want to scheduled a delayed reboot of my server in 5 seconds. So far, I have the below, but it takes 60 seconds …
# Timed reboot of server
sudo shutdown -r 1
# Fail if any of the sub-deployments failed.
if [[ ( $PROC1_STATUS -ne 0 ) ||
( $PROC2_STATUS -ne 0 ) ||
( $PROC3_STATUS -ne 0 ) ]]
then
exit 1;
fi
Does anyone know how I can adjust the above except make the timed reboot in 5 seconds instead of a minute? The solution doesn't have to use "shutdown" but it was the only tool I could find.
Dave
Try
sleep 5 ; reboot
on your terminal (as root). If you want it in the background, try
( sleep 5 ; reboot ) &
See also shutdown(8)

Turn off crontab log [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
The log file is located at /var/log/cron. Its size grows too fast and it seems to contain a lot of unimportant data that I would never want to see. So I try to find a way to turn it off but still don't know how.
Here are some more details about the crontab:
crontab -l
*/5 * * * * /usr/sbin/ntpdate 10.0.1.10
*/1 * * * * cd /tmp && netstat -an|awk '/tcp/ {print $6}'|sort|uniq -c > net.tmp && mv -f net.tmp net.cache
*/1 * * * * /script/svrcheck/openvpn.sh > /dev/null 2>&1
tail /var/log/cron
Dec 17 09:25:01 HB04 crond[54509]: (root) CMD (/usr/sbin/ntpdate 10.0.1.10)
Dec 17 09:25:01 HB04 crond[54500]: (root) CMD (/script/svrcheck/openvpn.sh > /dev/null 2>&1)
Dec 17 09:25:01 HB04 crond[54504]: (root) CMD (cd /tmp && netstat -an|awk '/tcp/ {print $6}'|sort|uniq -c > net.tmp && mv -f net.tmp net.cache)
Please let me know if I could provide you more info.
you can control logging using syslog.conf
comment the cron entry inside the syslog.conf as follows .
auth,authpriv.* /var/log/auth.log
*.*;auth,authpriv.none,cron.none -/var/log/syslog
#cron.* /var/log/cron
and restart the syslog.

Check a files Modified date and email if it has changed [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am look for a bash script that will check if a file has been modified in the last hour and email an alert if it has been modified. This script will be used in Solaris and Ubuntu. I am sure it's not hard, but I am not a Linux admin. Can someone please help?
How about this?
#!/bin/bash
[[ -z `find /home/spatel/ -mmin -60` ]]
if [ $? -eq 0 ]
then
echo -e "nothing has changed"
else
mail -s "file has been changed" spatel#example.com
fi
Put this script in hourly cron job
01 * * * * /path/to/myscript
linux supports the inotify command. You use it to monitor file activity - file change, file creation whatever you want, whenever you want.
The find command given above will not work on out-of-the-box solaris. It is fine for linux. You have two options on Solaris:
go to www.sunfreeware.com and download gnu coreutils, which will install gnu find (the above version of find) in /usr/local/bin
write a script that uses the touch command, wait more than 60 minutes then test the file, the only problem is this script runs in the background forever, you can avoid this if you know some perl to generate a timestring suitable for touch -t [time string] to create the file with a time one hour in the past
This is the run forever version:
while true
do
touch dummy
sleep 3615 # 1 hour 15 seconds
[ file_i_want_to_test -nt dummy ] && echo 'file blah changed' |
mailx -s 'file changed' me#myco.com
done

Resources