Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Debian sh, bash, and cron help
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Debian sh, bash, and cron help

ZealZeal Member
edited November 2015 in Help

Hello all,

I just installed cron on debian 7 32 bit minimal.
I'm trying to get firefox to restart every now and then while imacros is started with it.
(Sometimes I come back and firefox is magically disappeared, probably crashed.)

First I tried:

run.sh

    #!/bin/sh
    while [ true ]
    do
        sh commands.sh
        sleep 3600
    done

Plus commands.sh:

pkill -9 iceweasel;
firefox imacros://run/?m=emailrelog.iim;

However, I got a error with "done" command, i tried bash and sh to start the script, same error.
So I tried just "bash commands.sh", it worked, but I need it to be automatically done every hour.

Then I thought, maybe I use cron.
In the process I realized I needed a display selected so I tried the following.

Then I tried:
1 * * * * export DISPLAY=:1 && /bin/bash commands.sh

1) After I save the file, do I have to reboot computer or run a command?
2) Any other suggestions in other ways I can get my firefox to restart with imacros running?

I tried a good 3-4 hours and I'm hoping the community can lend a helping hand.

Thank you for all your help!
Have a nice day! ^_^

Comments

  • I'm stuck at the part where you want Firefox to restart by itself - presumably when you're not there. Why?

  • ZealZeal Member
    edited November 2015

    @Ole_Juul said:
    I'm stuck at the part where you want Firefox to restart by itself - presumably when you're not there. Why?

    Okay let me try explain.
    1) I save the imacros to a google drive folder, this way I can edit it remotely. (So I am not on desktop)

    2) The imacros automates task for me, which I can change without being at my computer.

    3) If firefox does not restart, then even though I change my imacros, firefox will be crashed/closed. My task does not complete automatically.

  • ZealZeal Member
    edited November 2015

    @Ole_Juul Could you help me out please? :D

  • 1) No you don't, if you used "crontab -e" instead of editing the file by yourself.

    2) This script looks good. However you may want to find firefox before trying to restart it. Don't know if it's your intension or not.

  • I guess you probably need to redirect the stdout, stderr, or better stdin to the blackhole /dev/null to avoid the process from being hooked to a terminal.

  • @msg7086 said:
    1) No you don't, if you used "crontab -e" instead of editing the file by yourself.

    2) This script looks good. However you may want to find firefox before trying to restart it. Don't know if it's your intension or not.

    Thank you, I will try that. :D

  • @elgs said:
    I guess you probably need to redirect the stdout, stderr, or better stdin to the blackhole /dev/null to avoid the process from being hooked to a terminal.

    Thank you too, will try this out aswell.

  • GM2015GM2015 Member
    edited November 2015

    When I wrote my backup scripts on ubuntu 14.04, I had no idea why cron wouldn't execute a backup script with command "bash /path/to/backup.sh".

    After googling around it needed a PATH=/whatever/ variable inside the script, which differs on my most OS-s.

    Try running

    env | grep PATH

    to find your PATH.

    On my debian wheezy boxes, the first 3 lines look like this:

    #!/bin/bash
    #find your PATH= by calling "env" in the terminal.
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    

    Compare that to debian jessie desktop:

    PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
    

    My script runs fine, so try the PATH below #!/bin/bash

  • singsingsingsing Member
    edited November 2015

    Zeal said: However, I got a error with "done" command, i tried bash and sh to start the script, same error. So I tried just "bash commands.sh", it worked, but I need it to be automatically done every hour.

    Clearly, your command.sh script is using bash features that are simply not present in sh.

    Change your original script's sh command.sh line to bash command.sh and it should work.

    My advice is to forget about cron entirely. To script something that runs periodically, I use exactly the technique of your first script (and stick an invocation in /etc/rc.local if it must be started at boot).

  • SadySady Member
    edited November 2015

    @GM2015 said:
    When I wrote my backup scripts on ubuntu 14.04, I had no idea why cron wouldn't execute a backup script with command "bash /path/to/bakup.sh".
    After googling around it needed a PATH=/whatever/ variable inside the script, which differs on my most OS-s.

    I second this, had to add "PATH" in my scripts (which are called by cron) too.

Sign In or Register to comment.