Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 32

Thread: at command launches script

  1. #21
    Join Date
    Aug 2006
    Beans
    428

    Re: at command launches script

    Yes TheFu, I did miss that. Sorry.

    So ... I changed

    Code:
    #!/bin/sh
    to

    Code:
    #!/bin/bash -x
    in a.sh.

    Alas with the same result.

    I think I am prepared to give up. I've wasted too much of my time on this as well as the time of a number of others.

    I find it just a bit incredible that getting a script to be triggered by at can be such a problem ...

  2. #22
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: at command launches script

    I asked for you to add a '-x' option to your bash script, run it, and post the output. Did you miss that?
    Dude, if you don't post the script and the output, we can't help. -x is a troubleshooting technique, not a "fix it" option.

    If you are trying to have the script do anything with a GUI, forgetaboutit. cron (and at) aren't designed for that purpose. If you are 1000 miles away from the computer, not logged in, but the computer is on, will your script do something useful?

    For example, I use 'at' to record TV shows from a network-based TV tuner. If the tuner is powered on and the computer is powered on, then the recordings happen. I don't need to be logged in. The files are recorded to /TV/Recordings/ with the show name, channel, and a timestamp.ts. Multiple shows can be recorded concurrently. There is no interaction with the GUI. The output from 'at' gets emailed to my email server.

    Last night it recorded...
    Code:
    INFO: Output file will be: "/TV/Recordings/Consuelo_Mack_WealthTrack-2021-07-08-232800-8.1.ts"
    --2021-07-08 23:28:00--  http://hdhr5:5004/auto/v8.1
    Resolving hdhr5 (hdhr5)... 172.22.22.25
    Connecting to hdhr5 (hdhr5)|172.22.22.25|:5004... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: unspecified [video/mpeg]
    Saving to: ‘/TV/Recordings/Consuelo_Mack_WealthTrack-2021-07-08-232800-8.1.ts’
    
         0K .......... .......... .......... .......... ..........  168K
        50K .......... .......... .......... .......... ..........  194K
       100K .......... .......... .......... .......... ..........  210K
       150K .......... .......... .......... .......... ..........  194K
       200K .......... .......... .......... .......... ..........  210K
    ....
    2263200K .......... .......... .......... .......... ..........  852K
    2263250K .......... .......... .......... .......... ..........  842K
    2263300K .......... .......... .......... .......... ..........  842K
    2263350K .......... .......... .......... .......... ..........  837K
    2263400K .......... .......... .......... .......... ..........  844K
    2263450K .......... .......... .......... .......... ..........  837K
    2263500K .......... .......... .......... .......... ..........  831K
    ERROR: 0
    That email message and the recorded video file are the only results. If I was logged into the system, the GUI wouldn't show anything, which is good, because it cannot. 'at' doesn't interact with any GUI.
    Last edited by TheFu; July 18th, 2021 at 03:33 PM.

  3. #23
    Join Date
    Aug 2006
    Beans
    428

    Re: at command launches script

    Unless I missed it (again) I don't think anyone expressed any desire to see the apparently offending script.

    That said, here it is:

    Code:
    #!/bin/bash -x
    #----------------------------------------------
    
    /usr/bin/firefox  https://www.bbc.co.uk/schedules/p00fzl7l https://www.bbc.co.uk/schedules/p00fzl7j https://www.thingiverse.com/search?q=tools&type=things&sort=newest&page=1
    As I indicated on multiple occasions it performs just fine with bash and with sh.

    Sorry but I have no idea where this GUI thing came from. It's a text file and launched with the command line.

  4. #24
    Join Date
    May 2010
    Beans
    1,631

    Re: at command launches script

    You must use the absolute path, starting from "/". If it is on your desktop (I don't suggest you store scripts there. It's messy) then you will need to specify the folders all the way to your desktop. Eg

    /home/yourusername/Desktop/a.sh

    This is an absolute path. The opposite is a relative path and is relative to your location that the shell is in. You can see this by running

    Code:
    pwd
    The at scheduler doesn't have this path, nor your BASH variables.

  5. #25
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: at command launches script

    Firefox is a GUI program. It won't work unless a user is logged in with an GUI session active, and the program is being run from inside that GUI session.
    cron and at aren't designed to work with GUI programs. They don't know what the current GUI session is. They don't know how to connect to the current GUI session. If you can use a mouse/trackpad, that is a GUI session.

    When you open a terminal inside a GUI session (Wayland or X/Windows), then that terminal inherits all the required settings for the current session. cron and at do not. I'm sorry. I don't know how to be any clearer.

    Take a look at alarm-clock-applet. This is a GUI tool where timers can be setup either for a specific time (9pm) or for a specific delay (2 hrs). A custom command can be put into it. The schedule is recalled after a reboot for any active timers and the times continue working.

    Also, you may want to use the xdg-open command instead of firefox. I have a script like this:
    Code:
    xdg-open http://pihole.lan/admin/index.php
    xdg-open https://darksky.net/forecast/
    xdg-open https://wb.lan/login
    sleep 4
    xdg-open https://nc.lan/nextcloud/login
    xdg-open http://istar.lan:32400/web/index.html#
    which will open tabs in an already running browser. Nothing wrong with using firefox either. Just providing an option.

    And the last URL has an '&' inside it. That is a special character in all shells and needs to be quoted or escaped so it gets passed through as an argument to the program. Need to 'https://www.thingiverse.com/search?q=tools&type=things&sort=newest&page=1' - single-quote it.
    Code:
    /usr/bin/firefox \ 
       https://www.bbc.co.uk/schedules/p00fzl7l \
       https://www.bbc.co.uk/schedules/p00fzl7j \
       'https://www.thingiverse.com/search?q=tools&type=things&sort=newest&page=1'
    alarm-clock-applet will work.

    If you are interested in recording audio from websites, there are non-GUI methods to do that. If the URL for the feed can be determined, wget can often be used with "timeout" to record to a file, but for a limited time. No GUI needed.
    Last edited by TheFu; July 18th, 2021 at 05:28 PM.

  6. #26
    Join Date
    Aug 2006
    Beans
    428

    Re: at command launches script

    My confusion continues.

    ActionParsnip seems to be suggesting that, if I EVER get the path right, this should work - i.e. "at" runs a script and the script "executes.

    You TheFu seems to be saying this will NEVER work.

    I still fail to understand why a typed in "sh" or "bash" on the command line works just fine. And the same commands typed in to an "at"command do/will not.

    Call me stoopid!

  7. #27
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: at command launches script

    If you tried the exact at command I provided in post #11 and that didn't work, then it is some other issue. Finally in post #23, we see that you are trying to run a GUI program. at and cron aren't designed to work with GUI programs. The environment is NOT the same.

    Have you ever used ssh to remote into another computer? There's no GUI. There's no GUI-session. You can't run any GUI programs on that remote system without doing something extra to make it work.

    If you use X/Windows, there are some terrible work-arounds, but I'm not gonna get into those because they are hacks of hacks and don't always work. I doubt Wayland will allow it at all. Wayland has more security.

    Use alarm-clock-applet. It will work for this purpose. Have you tried it?
    Last edited by TheFu; July 18th, 2021 at 06:09 PM. Reason: fixed incorrect words not-->no.

  8. #28
    Join Date
    Aug 2006
    Beans
    428

    Re: at command launches script

    i believe I have tried every suggestion offered in this thread. To no avail.

    And just to perhaps clarify, firefox is NOT running when I bash, or sh, the script. It opens firefox, successfully, all by itself. As you might find should you deign to do so.

  9. #29
    Join Date
    Aug 2006
    Beans
    428

    Re: at command launches script

    I guess I left a couple of loose ends ...

    I have never used ssh to remote into another computer?

    I do not use X/Windows.

    I have not tried the alarm-clock-applet?

    As I said earlier I have pretty much given up on this and somewhat regret starting the thread in the first place.

  10. #30
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,289
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: at command launches script

    You could try telling firefox which display you want it to use when it launches, like this:
    Code:
    #!/bin/bash -x
    #----------------------------------------------
    export DISPLAY=:0.0
    /usr/bin/firefox  https://www.bbc.co.uk/schedules/p00fzl7l https://www.bbc.co.uk/schedules/p00fzl7j https://www.thingiverse.com/search?q=tools&type=things&sort=newest&page=1
    but it will only work if you are logged in and running a graphical interface at the time it runs.
    If nobody is logged in, or if some other user is logged in then the at command will not be able to open a graphical application on that display.

    Like The FU tells you, at is not intended for launcing graphical apps. It is intended for running unattended programs that run in the background.

Page 3 of 4 FirstFirst 1234 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •