iwgetid in cron job

Forum rules
Before you post please read how to get help
Post Reply
Level 1
Level 1
Posts: 48
Joined: Thu Apr 04, 2013 12:17 pm

iwgetid in cron job

Post by nivedl » Tue May 15, 2018 12:06 pm

I have a script I wrote to automate my backup to 2 places, a local hard drive and to a cloud storage service. I only want the cloud backup to run when I am at work because my home internet connection is not great. To achieve this in the script I check the id of the current network using iwgetid -r. The script works as I expected when I run it from the terminal, but when I run it in a crob job it does not identify the name of the current network. Here is a minimal example:

NetName=$( iwgetid -r )
echo $NetName >> someFile.txt

When I run this in a cron job it only appends a blank line to someFile.txt, but when I run from the terminal directly it appends the network id. What is going on here?

User avatar
Level 10
Level 10
Posts: 3258
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher

Re: iwgetid in cron job

Post by smurphos » Wed May 16, 2018 3:13 am

How are you using Cron? Via a crontab or scripts dropped into one of the /etc/cron.* folders?

If the former you may need to specify the full path to iwgetid in the script or probably more convenient expand crons $PATH e.g by adding a line like this to the relevant crontab - PATH="/usr/bin:/bin:/usr/local/bin:/usr/sbin:/sbin:/usr/local/sbin"
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.

Post Reply

Return to “Scripts & Bash”