Permission denied error when running crontab [duplicate] - linux

This question already has answers here:
Running my program says "bash: ./program Permission denied" [closed]
(3 answers)
Closed 6 years ago.
I have created an r-script in the folder "csv_file"
marc#Marc-Linux:~/csv_file$ ls
8388.26580527145.csv csv_file.Rproj excel source write_csv2.R
Now I would like to create a crontab that executes this file every five minutes till 10am. Therefore I wrote the following
#open crontab
crontab -e
#add to file
*/5 10 * * * ~/csv_file/write_csv2.R
This however does not seem to work. That makes sense cause when I try to run
marc#Marc-Linux:~$ ~/csv_file/write_csv2.R
I get the following error:
-bash: /home/marc/csv_file/write_csv2.R: Permission denied
Any thoughts what goes wrong here?

make it executable first, using
chmod +x ~/csv_file/write_csv2/filename.r
and the execute it using ./filename.r

Related

what is use of `test -x` in Perl script execution [duplicate]

This question already has answers here:
what does command test -x do in ubuntu?
(2 answers)
Closed 3 years ago.
I am new to Perl !!!. I have one old crontab entry in sun OS machine to run a Perl script which goes like 10 * * * * test -x $path/abc.pl && $path/abc.pl >/dev/nul.
I want to know what is the use of term test -x in this execution.
test check file types (and permissions).
test -x FILE checks that FILE exists and execute (or search) permission is granted.
So, only if $path/abc.pl is an existing file and the current user has execute permission, it will be executed.
Refernce:
https://linux.die.net/man/1/test
BTW, this has nothing to do with Perl, although Perl has similar function:
https://perldoc.perl.org/functions/-X.html

Crontab on linux [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I can't understand, I have looked at several forums to help me, etc... But it still doesn't work!
I would like to run a script thanks to Cron!
To try, I'm currently trying to execute a script that sends "test" in commands (with echo test). No problem, this script works perfectly by hand if I call the file.
But I tried to run my file with Crontab -e every minute and I've been waiting for several minutes already, but no results.
And I can't really understand why!
Already, I was told to put #! /bin/bash at the beginning of my code in my script, but when I put it in I have an error and the code doesn't execute by hand. Whereas if I don't put anything in, the code runs smoothly.
So I don't know if that's where the mistake came from, maybe.....
The final goal would be to make a script that runs every day, say to clear the cache with sync; echo 3 > /proc/sys/vm/drop_caches.
What should look like in the Crontab : 00 20 * * * PATH if I'm not mistaken.
Do you have a solution to help me?
EDIT: -bash: /root/Discord/script/cache.sh: /bin/bash^M: bad interpreter: No such file or directory it's the error I got when I runned /root/Discord/script/cache.sh to execut my script. And that command works when I don't have #! /bin/bash. But that works when I used sh cache.sh in the directory, even with #! /bin/bash !
Crontabs don't print the output on your opened terminal. You need to either create a file and then append the output there to view or test if it works. You can refer this answer https://stackoverflow.com/a/28856563/7181668
But if you want to run a shell script file through cron then you need to make sure you have given executable permission to that file and then you can use the below command in crontab -e
* * * * * /bin/sh /home/myUser/scripts/test.sh

cron job error : "sqoop command not found" [duplicate]

This question already has answers here:
How to get CRON to call in the correct PATHs
(15 answers)
Closed last year.
After installing sqoop successfully, i wrote a script "sqoop.sh" and kept in another folder. In terminal, I am able to execute sqoop script by giving command ./sqoop.sh. It works fine. Now when i try to add a cronjob of this, error message "sqoop command not found".
Here is sample -
45 * * * * /home/user/Desktop/hadoop/sqoop/sqoop_script/sqoop.sh
You can add the location of Sqoop's bin directory to the PATH. For example, when using bash shell, you can add these lines to the .bash_profile.
export SQOOP_HOME=/usr/hdp/current/sqoop-client
export PATH=$PATH:$SQOOP_HOME/bin

.bat file is not executing on Linux server [duplicate]

This question already has an answer here:
Why would a correct shell script give a wrapped/truncated/corrupted error message? [duplicate]
(1 answer)
Closed 6 years ago.
I've made a simple bat file "run_perl.bat" that executes a Perl script "Oncomine_main.pl" in \data\test_scripts directory.
Here is the content of the bat file:
cd /data/test_scripts
perl Oncomine_main.pl
I run the script from the login directory
Here is what is returned to me:
[username#path-twood3 ~]$ ./run_perl.bat
: No such file or directory /data/test_scripts
": No such file or directorymine_main.pl
Please suggest how to fix this issue?
Thank you
Add #!/bin/sh as the first line of run_perl.bat.

how to run a bash script with multiple lines on crontab [duplicate]

This question already has answers here:
cronjob does not execute a script that works fine standalone
(3 answers)
Closed 6 years ago.
Because vpnc stopped every ~23 hours, I created a .sh file that is running as a cron job every 10 minutes, all that it does, is stop the vpnc process and run it again.
I have made it executable by chmod + x ping_vpnc.sh and it works fine when I run it from the terminal via ./ping_vpnc.sh
My file looks similar to:
#!/bin/sh
killall vpnc #just to make sure I don't create too many tunnels.
vpnc default.conf #run vpnc connect file.
my crontab file:
*/10 * * * * /home/username/ping_vpnc.sh
the problem with the script that it does't run fully, so it just kill the process without re-running it.
I'm running the script as root so I don't think that it's a privilege issue.
Any idea about why this is happening? I will appreciate it.
As indicated on comments, change
*/10 * * * * /home/username/ping_vpnc.sh
for
*/10 * * * * /bin/sh /home/username/ping_vpnc.sh
that is, tell crontab which binary has to execute the script.
For future references, let me point out the question you found in Ask Ubuntu: Script doesn't run via crontab but works fine standalone. It provides comprehensive information about the topic.

Resources