this post was submitted on 28 Aug 2025
18 points (95.0% liked)

Linux

57752 readers
541 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 6 years ago
MODERATORS
 

Hi

When I setup a cron job like this crontab -e

*/1 * * * * echo $A_VARIABLE > /home/user/Desktop/test.txt

no problem, the file is created whether the variable exist or not.

BUT doing

*/1 * * * * cd /Path/To/Script && Script.sh
#The Script.sh
echo $A_VARIABLE > /home/user/Desktop/test.txt

Do not generate the file ! and The CRON log give me

(CRON) info (No MTA installed, discaring ouput)

and yes, the  Script.sh has the execution bit.

Any ideas ?

Thanks.

top 8 comments
sorted by: hot top controversial new old
[–] I_Am_Jacks_____@sh.itjust.works 13 points 1 day ago* (last edited 1 day ago) (1 children)

If . or /path/to/Script are not in your crontab's PATH variable, it cannot find the script. If the script is in /path/to/Script, change your crontab to either:

*/1 * * * * cd /Path/To/Script && ./Script.sh

Or

*/1 * * * * /Path/To/Script/Script.sh

Also, "*/1" means every 1 minute and "*" means every minute, so the "/1" is unnecessary

[–] ozoned@piefed.social 6 points 1 day ago* (last edited 1 day ago)

This is the answer. Everyone assumes your user Crontab works just like you. It doesn't. You have to be explicit as possible, because it's basically like another person attempting to run your stuff, but not having any of your environment variables.

So you're telling it to CD, but calling the script name then tells it to look in it's path, which it won't have that. T

he ./ says 'run from right where I am right now' while '' says run an executable where ever it is which then immediately checks $PATH, bit not local.

So './' says run my script and it's right HERE in the place you're in right now.

Thanks everyone,

I figured out also the missing ./ but meanwhile I got already 4 reply ! \

Thanks so much !

[–] AnnaFrankfurter@lemmy.ml 3 points 1 day ago (1 children)

I see you already got the answer. But if you are new to Linux I'd suggest to play overtwire bandit. This will significantly improve your Linux command knowledge.

+1 for bandit. I’m working on natas now! :)

[–] cerement@slrpnk.net 1 points 1 day ago

(sidetrack: crontab guru helps you make sense of the first part of each crontab line)

[–] Juno@lemmy.world 2 points 1 day ago

User permissions? I’m no pro, but when running the script it might not have the right permissions for /home/user/? Hopefully someone smarter at this can teach us both…

[–] diesch@loma.ml 1 points 1 day ago

@SpongeB0B By default Linux shells don't look in the current folder for executables. Use "./Script.sh" instead of "Script.sh" to start the script.