iwgetid in cron job

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
nivedl

iwgetid in cron job

Post by nivedl »

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:

#!/bin/bash
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?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: iwgetid in cron job

Post by smurphos »

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.
Locked

Return to “Scripts & Bash”