Monday, May 6, 2024
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 1245  / 2 Years ago, fri, june 3, 2022, 11:15:58

I made a shell script called /home/root/cron_grads.sh (chmodded 755) on my server.



In this directory are more grads-scripts like 500hPa_p0.gs (644). My main script creates a temporary file grads_exec.gs, fills it with some content and then tries to copy the content of 500hPa_p0.gs onto the end of it before executing the whole thing This works fine, even on the server if I start it manually.



But using crontab -e with:



42 0,6,12,18 * * * /home/root/grads/cron_grads.sh


... an error occurs. The script starts but grads says:



cat: 500hPa_p0.gs: File or directory not found


I am using bash in cron_grads.sh with #!/bin/bash at the top in it. crontab -e also contains SHELL=/bin/bash.



Any ideas?


More From » command-line

 Answers
7

This is an issue within your cron_grads.sh script. When you call it manually, I assume you're in /home/root so it would run something like:



echo test > grads_exec.gs
cat 500hPa_p0.gs >> grads_exec.gs


But if you ran that from while at /home/oli/, it would attempt to write to /home/oli/grads_exec.gs and read from /home/oli/500hPa_p0.gs. That's why cat is blowing up in your case.



To fix, either explicitly cd into the right directory (and use an absolute path):



cd /home/root
echo test > grads_exec.gs
cat 500hPa_p0.gs >> grads_exec.gs


Or use absolute paths everywhere:



echo test > /home/root/grads_exec.gs
cat /home/root/500hPa_p0.gs >> /home/root/grads_exec.gs


Or for safety's sake, both.


[#24909] Saturday, June 4, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leadprogres

Total Points: 298
Total Questions: 114
Total Answers: 139

Location: Samoa
Member since Mon, Nov 8, 2021
3 Years ago
;