I am having confusion in touch command
while i execute "touch -m 0303 10 30 filename" it should actually update the modification time to
03 - march
03 - date
10 hours
30 - min
But while executing it is creating 5 empty files
named 03 03 10 30 filename
I executed this command in OSX
Try this command line, Instead of taking the current time-stamp, you can explicitly specify the time using -t flag.
The format for specifying -t is [[CC]YY]MMDDhhmm[.SS]
touch -m -t 03041030 filename
Read man touch again. -m doesn't take any arguments, you have to add -t or -d (I'm not sure whether both options are available on OSX).
Related
I'm trying to schedule a bash script using at command on Linux.
at 22:20 -f /path/to/script.sh
Issuing the command above works just fine. However, the script requires some parameters. Adding Params behind the script path returns an error message:
at 22:20 -f /path/to/script.sh /arg/one argtwo argthree
syntax error. Last token seen: /
Yes, the first parameter passed to the script is another (absolute) path. My guess is, that at doesn't treat my script as a script but rather as a file, as at -help implies.
How can I work around that and add params to the script?
Specify the command to run on stdin, e.g. via a here string:
at 22:20 <<< "/path/to/script.sh /arg/one argtwo argthree"
Your command does not try to run /path/to/script.sh at a certain time. Instead, it reads and copies all the commands from /path/to/script.sh and runs those later. Since you're not invoking the script itself, it doesn't make sense to talk about arguments.
You're correct that it's taking just a filename, not a command. You should just run at 22:20, and then as input to that command, give the command you want run at 22:20 (i.e. /path/to/script.sh /arg/one argtwo argthree), and then Control-D on a separate line to mark the end of input. It should look a little like this ($ is my prompt):
$ at 22:20
/path/to/script.sh /arg/one argtwo argthree
job 11 at Thu May 27 22:20:00 2021
$
(Note that the "job 11 ..." is a confirmation message at printed.)
You can give any command as input without the -f:
at 22:20
/path/to/script.sh /arg/one argtwo argthree
^d
I would like to run a specific script at a certain time (only once!). If I run it normally like this:
marc#Marc-Linux:~/tennis_betting_strategy1/wrappers$ Rscript write_csv2.R
It does work. I however would like to program it in a cronjob to run at 10:50 and therefore did the following:
50 10 11 05 * Rscript ~/csv_file/write_csv.R
This does not seem to work however. Any thoughts where I go wrong? These are the details of the cron package im
using:
PID COMMAND
1015 cron
My system time also checks out:
marc#Marc-Linux:~/tennis_betting_strategy1/wrappers$ date
wo mei 11 10:56:46 CEST 2016
There is a special tool for running commands only once - at.
With at you can schedule a command like this:
at 09:05 am today
at> enter you commands...
Note, you'll need the atd daemon running.
Your crontab entry looks okay, however. I'd suggest checking if the cron daemon is running(exact daemon name depends on the cron package; it could be cron, crond, or vixie-cron, for instance). One way to check if the daemon is running is to use the ps command, e.g.:
$ ps -C cron -o pid,args
PID COMMAND
306 /usr/sbin/cron
Some advices.
Read more about the PATH variable. Notice that it is set differently in interactive shells (see your ~/.bashrc) and in cron or at jobs. See also this about Rscript.
Replace your command by a shell script, e.g. in ~/bin/myrscriptjob.sh
That myrscriptjob.sh file should start with #!/bin/sh
Be sure to make that shell script executable:
chmod u+x ~/bin/myrscriptjob.sh
Add some logging in your shell script, near the start; either use logger(1) or at least some date(1) command suitably redirected, or even both:
#!/bin/sh
# file myrscriptjob.sh
/bin/date +"myrscriptjob starting %c %n" > /tmp/myrscriptjob.start
/usr/bin/logger -t myrscript job starting $$
/usr/local/bin/Rscript $HOME/csv_file/write_csv.R
in the last line above, replace /usr/local/bin/Rscript by the output of which Rscript done in some interactive terminal.
Notice that you should not use ~ (but replace them with $HOME when appropriate) in shell scripts.
Finally, use at to run your script once. If you want to run it periodically in a crontab job, give the absolute path, e.g.
5 09 11 05 * $HOME/bin/myrscriptjob.sh
and check in /tmp/myrscriptjob.start and in your system log if it has started successfully.
BTW, in your myrscriptjob.sh script, you might replace the first line #!/bin/sh with #!/bin/sh -vx (then the shell is verbose about execution, and cron or at will send you some email). See dash(1), bash(1), execve(2)
Use full path (started from /) for both Rscript and write_csv2.R. Check sample command as follows
/tmp/myscript/Rscript /tmp/myfile/write_csv2.R
Ensure you have execution permission of Rscript and write permission in folder where write_csv2.R will be created(/tmp/myfile)
After research the whole Internet can't find a solution to it.
I have a script which is working perfectly when I execute it from terminal.
#!/bin/bash
zip -r -j Tato.zip Csv
rm -r Csv/*.*
echo "blahblahblah" | mutt -s "Test" email#gmail.com -a Tato.zip
rm *.zip
but actually it does not work when I put it inside a crontab.
55 15 * * 7 /home/pi/Script.sh
wanted it to be executed on Sundays at 15.55.
And this is the output that /var/log/syslog tells me
Nov 1 15:55:01 raspberrypi sSMTP[3939]: Unable to locate mail
Nov 1 15:55:01 raspberrypi sSMTP[3939]: Cannot open mail:25
Nov 1 15:55:01 raspberrypi /USR/SBIN/CRON[3936]: (pi) MAIL (mailed 1 byte of output; but got status 0x0001, #012)
Don't know what to do anymore.
All help will be appreciated.
I want to copy updated file from one server to another every 15 min when the new file gets generated. I have written code using expect script. It works fine but after 15 min it copies all the files in the directory i.e. it replaces and copy latest one also. I want only updated file (updated every 15 min) to get copied and not all the files.
Here is my script:
while :
do
expect -c "spawn scp -P $Port sftpuser#$IP_APP:/mnt/oam/PmCounters/LBO* Test/;expect \"password\";send \"password\r\";expect eof"
sleep 900
done
can I use rsync or any other approach and how?
rsync does only copy changed or new file by default. Use for example that syntax:
rsync -avz -e ssh remoteuser#remotehost:/remote/dir /local/dir/
That specifies ssh as remote shell to use (-e ssh ...), -a activates archive mode, -v sets verbose output and -z compresses the transfer.
You could run that every 15 minutes by a cronjob.
For the password you can use the $RSYNC_PASSWORD environment variable or the --password-file flag.
I have to start a cronjob on every Thursday. Here is the script.
It will not start at all.
Manually it does his work but not as a cronjob.
It should start at 17.00 every Thursday:
00 17 * * 4 root cd /var/www/domein.nl/admin/scripts && php -f send_newsletter_subscribers.php
also tried to do as text: wed
33 15 * * wed root cd /var/www/domein.nl/admin/scripts && php -f send_newsletter_subscribers.php
Have no idea why it doesn't work.
Does anybody have any suggestion what I'm doing wrong?
Thanks in advance for replying.
Is this an individual user's crontab (edited with crontab -e) or a system level crontab file? If the former, then the syntax is wrong, and you need to remove the user specification ("root").
The time and date fields look fine.
Think about setting some important variables in your /etc/initab (specially PATH and SHELL).
My /etc/initab file contains the following:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/root