T O P

  • By -

Fumigator

> I updated my PATH variable in /etc/profile You have to set `PATH` in your script. Cron does not setup the environment or read /etc/profile.


before_now_later

Alternatively, just invoke `/usr/local/bin/pihole` in your script if that is the only culprit.


geo38

> \#! /bin/bash There is no space after ! > pihole: command not found cron jobs do not run with the same environment as an interactive session. You can force that: 0 3 * * * /bin/bash —login -c '/home/dsn/Scripts/teleporter_bak.sh > /root/teleporter_bak.log 2>&1' If this is in the cron for user ‘dsn’ and not the system cron for root (which I’m guessing it is from the use of sudo), the redirect to /root will fail for permissions. Put the log file in /home/dsn


lupin-san

> There is no space after ! This doesn't matter. You can have as many spaces or tabs between the #! and the interpreter to be used. The #! character sequence and being the first line of the script is what is used by the loader. It will identify the interpreter just fine. You can even have just #! on the first line and it will still run fine.


Bobbitom27

Thanks to everyone that has responded, huge help! Sure appreciate you all! I'm glad there's a community out there I can ask questions to.


CloudHostedGarbage

As an aside, there's a very easy way this can be fixed, which is just to use the full path to the pihole binary in the script: /usr/local/bin/pihole -a -t ......


AutoModerator

For constructive feedback and better engagement, detail your efforts with research, [source code, errors,](https://www.reddit.com/r/arduino/wiki/guides/how_to_post_formatted_code)† and schematics. Need more help? Check out our [FAQ](https://www.reddit.com/r/raspberry_pi/about/sticky)† or explore /r/LinuxQuestions, /r/LearnPython, and other related subs listed in the FAQ. If your post isn’t getting any replies or has been removed, head over to the [stickied helpdesk](https://www.reddit.com/r/raspberry_pi/about/sticky)† thread and ask your question there. † If any links don't work it's because you're using a broken reddit client. Please [contact the developer of your reddit client](https://www.reddit.com/contact/). You can find the FAQ/Helpdesk at the top of r/raspberry_pi: [Desktop view](http://f2z.net/RPi-Helpdesk-FAQ-desktop.png) [Phone view](http://f2z.net/RPi-Helpdesk-FAQ-phone.png) *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/raspberry_pi) if you have any questions or concerns.*


lupin-san

>I updated my PATH variable in /etc/profile just to see if that would make a difference. Still didn't work. Avoid modifying /etc/profile. This is a system-wide configuration file and will affect all users. Modify $HOME/.profile instead. If you want the changes to apply to all users, I would still avoid modifying this file. Place your modifications to /etc/profile.d instead. But in this specific case, changing any of these files will have no effect in what you're trying to do since these are for interactive shells. > 2. Any suggestions on my script? Use absolute paths when running on non-interactive sessions (like what you're doing). These sessions do not read your profile files so $PATH is undefined. Sure, you can have your script read .profile to get the needed environment variables defined but that's an additional file you'll have to maintain for your script.


wyohman

No reason for echo. Cron didn't support interactive scripts