0

I would appreciate advice on why a script would run fine when the script is launched from a terminal command line, but some commands in the script seemingly do not run when the script is scheduled using the "at" command (and advice on how to get it to run correctly when scheduled). The script (named "open_browser.sh") is intended to open a browser at a scheduled time as follows:

#!bin/bash
#script filename: "~/Desktop/open_browser.sh"

#write to log file to verify script is running
echo "Starting open_browser.sh"

#set URL for browser
STRING = "https://news.google.com/"

#open browser - try with Firefox and Chromium
#firefox $STRING
chromium-browser $STRING

#write to log file to verify script finishes
echo "Ending open_browser.sh"

#end of script

When I run the script from a terminal command line using "./~/Desktop/open_browser.sh > log_file", the script opens the selected browser in a visible (foreground) window and writes the echo statements to the log file. When I schedule the script with the "at" command, it opens the log file and writes all echo messages, but it does not open any visible browser window. I scheduled the script using "at" as follows:

$ at now + 1 min 

at> ./~/Desktop/open_browser.sh > log_file

I would be grateful for any insight as to why the script would open a browser when executed from the command line but seemingly not when scheduled using the "at" command.

For additional information, my installation has the default "at" deny file (/etc/at.deny). I did not see any at.allow file.

Thanks in advance.

6
  • Apologies for the fonts. For some reason, the comment lines in the script appear as bold font when I typed them with a # sign.
    – stuart_h
    Feb 19, 2020 at 10:01
  • Use the {} at the formatting tools for this ;)
    – Rinzwind
    Feb 19, 2020 at 10:07
  • I would assume ./~/Desktop/open_browser.sh is not a valid command. Use a full path instead of a ~. The ~ is a BASH addition evaluated when executing it using bash. at probably does not use bash or it it does it does not evaluate the ~ If that is the solution feel free to comment so I can post it OR make the answer yourself and accept that answer :)
    – Rinzwind
    Feb 19, 2020 at 10:09
  • Your command chromium-browser runs in a shell but needs a graphical display. You don't specify one, whereas you may have many. Your default display is called :0. You also need to specify the full path to each executable. Try replacing the command by DISPLAY=:0 /usr/bin/chromium-browser $string.
    – Jos
    Feb 19, 2020 at 10:15
  • Rinzwind: Thank you for tip on formatting. As to at parsing the ~, I believe it does, as the script runs (when scheduled using at) as evidenced by the creation of the log file and the writing of the echo statements. Gratitude for the help.
    – stuart_h
    Feb 20, 2020 at 1:29

1 Answer 1

0

Jos' answer was a correct solution. "Your command chromium-browser runs in a shell but needs a graphical display. You don't specify one, whereas you may have many. Your default display is called :0. You also need to specify the full path to each executable. Try replacing the command by DISPLAY=:0 /usr/bin/chromium-browser $string."

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .