Script for scheduling Dataone connection in Opensuse

Status
Not open for further replies.

arupch

Tech Addict
Hi,
I'm using OpenSuse 11.0.
I've a Dataone broadband connection in bridged mode. I use Kinternet to manually connect to internet. I've a limited bandwith net connection which provides unlimited downloads between 2.00-8.00AM.
I've tried to keep running my net connection and scheduling downloads in Ktorrent. But when kept idle, the connecion disconnects after sometime. I've entered Idle Time Out as 0 in DSL settings.

Executing sudo -i and /sbin/ifup dsl0 from terminal starts the net.

I've tried making a script as follows and running it using Kcron

#!/bin/bash
sudo -i
/sbin/ifup dsl0
exit 0

I've removed password for sudo by using Yast also made the file executible from the properties.
But this doesn't work.

Now pls tell me why?


______________
Arup
 

mediator

Technomancer
"sudo -i" is irrelevant. The logic lies in adding to cron a timing from 2-8, that executes the script every minute or 5 minutes whicheva u like. I had made a script for similar purpose. Here's the modified one for ur use.

#!/bin/bash

cd /home/scripts/
ping 208.67.222.222
-c 1 > /dev/null
val=`echo $?`

if [ $val -ne 0 ];then

echo "--> Restarting" >> autostart.log
date >> autostart.log
echo "******************" >> autostart.log

#Command that starts the connection, you can edit this
/sbin/ifup dsl0

fi
1. Save n Name the script say, "nightrider.sh" to a folder say, "/home/scripts" where all ur other scripts are stored.
2. command "chmod +x nightrider.sh" for making it executable
3. For cron u do
*/5 2-8 * * * /home/scripts/nightrider.sh
The IP 208.67.222.222 belongs to opendns. It is only there for checking the internet connection status. "autostart.log" is the log generated that shows "when" the script was executed. I hope it works!
 
OP
A

arupch

Tech Addict
Hi,
#!/bin/bash
sudo -i
/sbin/ifup dsl0
exit 0

Thank you for your reply.
I'll try that.
But above when saved as a file (dsl.sh) and made executible does not starts net when run from terminal.
whyyy??
___________
Arup
 

mediator

Technomancer
U must understand then how the shell scripts work. When u put sudo or su, u r simply "entering" a "new shell" which doesn't know about next lines/commands in the script. So it doesn't matter if u have a password for root or not. It is wrong to put "sudo" in a shell script!

U can remove the sudo part i.e "sudo -i" and initiate the script u created as "sudo sh dsl.sh". U can also remove the "exit 0" part as well..
 
OP
A

arupch

Tech Addict
Thank you for your help. I'm trying to get this issue solved for several days in different forums - but nobody except you helped.

I tried your script: i saved the file as test.sh in desktop - also changed the path statement in the script.

Then executed ./test.sh

Which gave me:
/sbin/ifup: line 207: /dev/shm/sysconfig/config-dsl0: Permission denied
dsl0
error: can't create pid file, Permission denied
error: can't create pid file
failed to bring interface dsl0 up
awk: cmd. line:1: fatal: cannot open file `/etc/ntp.conf' for reading (Permission denied)
awk: cmd. line:1: fatal: cannot open file `/etc/ntp.conf' for reading (Permission denied)
Checking for network time protocol daemon (NTPD): unused
arup@linux-9c3u:~/Desktop> touch: cannot touch `/dev/shm/sysconfig/ready-dsl0': Permission denied

But when I give sudo sh test.sh it works:

dsl0
interface dsl0 is up
Checking for network time protocol daemon (NTPD): unused

So how do I put the Cronjob?
 

mediator

Technomancer
sudo crontab -e. I hope u know how to use the "vi editor"! Its really simple.

arupch said:
Thank you for your help. I'm trying to get this issue solved for several days in different forums - but nobody except you helped.
You're Welcome. :)
 

NucleusKore

TheSaint
Arupch, it would be nice if you could write a final post detailing the complete instructions and your experience it would be useful for other users, and maybe post the script too.
 

praka123

left this forum longback
@arupch: ifup and all need root permission. why not run the script as root(risky may be!) ,as cron can only execute those commands as su -.
 
OP
A

arupch

Tech Addict
Well. Thanks Mediator once again.
I've set the Cronjob as guided by you.
I'll write the detailed steps followed by me soon.

.................

Here are the steps that I followed.
All the credits goes to Mediator - I just followed his instructions.

The logic lies in adding to cron a timing from 2-8, that executes the script every minute or 5 minutes whicheva u like. I had made a script for similar purpose. Here's the modified one for ur use.

#!/bin/bash

cd /home/scripts/
ping 208.67.222.222 -c 1 > /dev/null
val=`echo $?`

if [ $val -ne 0 ];then

echo "--> Restarting" >> autostart.log
date >> autostart.log
echo "******************" >> autostart.log

#Command that starts the connection, you can edit this
/sbin/ifup dsl0

fi

1. Save n Name the script say, "nightrider.sh" to a folder say, "/home/scripts" where all ur other scripts are stored.
2. command "chmod +x nightrider.sh" for making it executable
3. sudo crontab -e.
4. For cron u do */5 2-8 * * * /home/scripts/nightrider.sh
The IP 208.67.222.222 belongs to opendns. It is only there for checking the internet connection status. "autostart.log" is the log generated that shows "when" the script was executed.

____________
Arup
 
Last edited:
Status
Not open for further replies.
Top Bottom