DIGIT-ARC read-only archive · snapshot: July 23, 2026

Script for scheduling Dataone connection in Opensuse

10 posts · originally from https://geek.digit.in/community/threads/script-for-scheduling-dataone-connection-in-opensuse.93497/

A
arupch Original post #1
Jul 19, 2008 at 7:54 PM
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
Jul 20, 2008 at 12:01 AM
"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!
A
arupch #3
Jul 20, 2008 at 9:52 AM
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
Jul 20, 2008 at 1:18 PM
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..
A
arupch #5
Jul 20, 2008 at 7:12 PM
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
Jul 20, 2008 at 11:00 PM
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
Jul 21, 2008 at 8:47 AM
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
Jul 21, 2008 at 9:01 AM
@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 -.
A
arupch #9
Jul 21, 2008 at 10:05 AM
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