Jump to content

Hi,

I've currently got 2 bash scripts within crontab

# m     h  dom mon dow   command
  */10  *   *   *  *    /etc/greenwich/grerpi.sh
  */10  *   *   *  *    /etc/greenwich/newrpi.sh

 

but it only runs the grerpi.sh bash script

 

grerpi.sh

#!/bin/bash
targetFile="/etc/network/grerpi"
address="192.168.1.1"
netmask="255.255.255.0"
channel="1"
essid="GreRPi"
password="/etc/greenwich/pswfile.log"
random=$(pwgen 13 -1)
{
        echo "$random"
} | sudo tee "$password" > /dev/null
{
        echo "source-directory /etc/network/interfaces.d"
        echo "auto lo"
        echo "auto wlan0"
        echo "allow-hotplug wlan0"
        echo "iface wlan0 inet static"
        echo "address $address"
        echo "netmask $netmask"
        echo "wireless-channel $channel"
        echo "wireless-essid $essid"
        echo "wireless-mode ad-hoc"
        echo "wireless-key s:$random"
} | sudo tee "$targetFile" > /dev/null
        scp "$targetFile" pi@192.168.1.1:~/.ssh/

 

newpi.shi

!/bin/bash
targetFile="/etc/network/interfaces2"
address="192.168.1.2"
netmask="255.255.255.0"
channel="1"
essid="GreRPi"
password=$(sudo cat "/etc/greenwich/pswfile.log")
{
        echo "source-directory /etc/network/interfaces.d"
        echo "auto lo"
        echo "auto wlan0"
        echo "allow-hotplug wlan0"
        echo "iface wlan0 inet static"
        echo "address $address"
        echo "netmask $netmask"
        echo "wireless-channel $channel"
        echo "wireless-essid $essid"
        echo "wireless-mode ad-hoc"
        echo "wireless-key s:$password"
} | sudo tee "$targetFile" > /dev/null
        sudo service networking restart

 

Any Suggestions?

 

Thank you

Link to comment
https://linustechtips.com/topic/744350-bash-script-cron-only-running-1-bash-script/
Share on other sites

Link to post
Share on other sites

13 minutes ago, spbr said:

Hi,

I've currently got 2 bash scripts within crontab


# m     h  dom mon dow   command
  */10  *   *   *  *    /etc/greenwich/grerpi.sh
  */10  *   *   *  *    /etc/greenwich/newrpi.sh

 

but it only runs the grerpi.sh bash script

 

grerpi.sh


#!/bin/bash
targetFile="/etc/network/grerpi"
address="192.168.1.1"
netmask="255.255.255.0"
channel="1"
essid="GreRPi"
password="/etc/greenwich/pswfile.log"
random=$(pwgen 13 -1)
{
        echo "$random"
} | sudo tee "$password" > /dev/null
{
        echo "source-directory /etc/network/interfaces.d"
        echo "auto lo"
        echo "auto wlan0"
        echo "allow-hotplug wlan0"
        echo "iface wlan0 inet static"
        echo "address $address"
        echo "netmask $netmask"
        echo "wireless-channel $channel"
        echo "wireless-essid $essid"
        echo "wireless-mode ad-hoc"
        echo "wireless-key s:$random"
} | sudo tee "$targetFile" > /dev/null
        scp "$targetFile" pi@192.168.1.1:~/.ssh/

 

newpi.shi


!/bin/bash
targetFile="/etc/network/interfaces2"
address="192.168.1.2"
netmask="255.255.255.0"
channel="1"
essid="GreRPi"
password=$(sudo cat "/etc/greenwich/pswfile.log")
{
        echo "source-directory /etc/network/interfaces.d"
        echo "auto lo"
        echo "auto wlan0"
        echo "allow-hotplug wlan0"
        echo "iface wlan0 inet static"
        echo "address $address"
        echo "netmask $netmask"
        echo "wireless-channel $channel"
        echo "wireless-essid $essid"
        echo "wireless-mode ad-hoc"
        echo "wireless-key s:$password"
} | sudo tee "$targetFile" > /dev/null
        sudo service networking restart

 

Any Suggestions?

 

Thank you

can you run the second script from SSH or direct?
If not then you need to make it executable.
It might point out some errors if you've got any.

Link to post
Share on other sites

5 minutes ago, Electronics Wizardy said:

since there running at the same time, just make a cron job that will run both of those.

 

And im assuming then work fine normally. You missing the comment of the fist line on the second one.

 

 

 

Thank you

How would you create a cron job, because i've done the same with crontab -e into /etc/crontab, I just don't see why it won't run two bash scripts.

 

Which comment from where am I'm missing?

 

Thank you

Link to post
Share on other sites

1 minute ago, leonfagan71 said:

can you run the second script from SSH or direct?
If not then you need to make it executable.
It might point out some errors if you've got any.

 

I can run all the bash scripts from the command line

 

Thank you

Link to post
Share on other sites

Just now, spbr said:

Thank you

How would you create a cron job, because i've done the same with crontab -e into /etc/crontab, I just don't see why it won't run two bash scripts.

 

Which comment from where am I'm missing?

 

Thank you

for comment first line is !/bin/bash, should be #!/bin/bash

 

for the script, make anouther one like this

 

/path/to/first/script.sh && /path/to/second/script.sh

 

also it is okay for them to be executing at the same time?

 

and you can test exectuing by putting soemthing like

 

touch /home/user/iran

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×