Find the answer to your Linux question:
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 28
Hi, for a friend I'm trying to create a simple script so he can reset his WiFi connection. Normally, we use su {type password} dhcpcd -t 10 -d ath0 exit ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99

    Do a su logon via a script


    Hi,

    for a friend I'm trying to create a simple script so he can reset his WiFi connection.

    Normally, we use

    su
    {type password}
    dhcpcd -t 10 -d ath0
    exit

    Now, is it possible to pass the root password via bash/the shell?

    I would really appreciate your help, or another suggestion if this is not the right way to solve this problem.

    Sincerely,

    Marinus.

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,844
    Just set the sticky bit for the script, it'll run as root then with no need to log in as root during script:

    chmod u+s <script_filename>
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99
    Hi Roxof,

    we tried that but it doesn't work for two reasons:

    **** /sbin/dhcpcd: not a superuser

    plus we want to rm the

    /etc/dhcpc/dhcpcd-ath0.pid

    if it exists.
    But then the scripts comes back with

    rm: remove write-protected regular file `/etc/dhcpc/dhcpcd-ath0.pid'

    Thanks for you help, hope you know a tweak here.

    Marinus.

  4. #4
    Linux Guru bigtomrodney's Avatar
    Join Date
    Nov 2004
    Location
    Ireland
    Posts
    6,127
    Would you have it prompt for root password during the script?

  5. #5
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99
    Yea that's ok, but rather I'd pass it in the script.
    The thing is that he's novice, and has a very very jurassic laptop that he just wants to use for the kids so they can go to disney.com.

    Every now and then the WiFi drops so he want to just click an icon and reset it.

    The less steps the better, but that would be ok.
    Is it possible to do that via a graphical (standard of some sort) prompt.
    A terminal popup that prompts is ok too, as long as it closes as the last part of the script.

    Thx,

    Marinus.

  6. #6
    Linux Guru dylunio's Avatar
    Join Date
    Aug 2004
    Location
    Cymru
    Posts
    4,157
    Quote Originally Posted by bigtomrodney
    Would you have it prompt for root password during the script?
    I think this would have to be done since one can't
    Code:
    echo "rootpw" | su
    since su needs to be invoked from the terminal, and anyway it's realy unsecure to write your root password anywhere, especialy on your computer.
    Registered Linux User #371543!
    Get force-get May The Source Be With You
    /dev/null
    /dev/null2

  7. #7
    Linux Guru bigtomrodney's Avatar
    Join Date
    Nov 2004
    Location
    Ireland
    Posts
    6,127
    What about a cron task that runs every few minutes, checks network availability and reestblished connectivity when needed? Cron tasks run as root anyway. Plus would negate any user intervention. The trick is how often you have it poll for connectivity, as you want it to remain up, but at the same time not have a large overhead. If it's KDE you're using you could use Kinternet to manage the connection through the GUI, Gnome has a network monitor for the panel that does something similar too.

  8. #8
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99
    Hi bigtomrodney,

    I have never tried a cron task. It sounds like a solution.
    We use KDE, but even that is a bit too advanced for him.
    Plus, does that renew the dhcpcd?

  9. #9
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99
    bigtomrodney,

    I just read up on cron and I have set it up now.
    Thanks for you help.
    I will just have to tweak the script now.
    How would you check for network availability?


    Thanks for you help.

  10. #10
    Linux Guru dylunio's Avatar
    Join Date
    Aug 2004
    Location
    Cymru
    Posts
    4,157
    I've made the following script, and it should work:
    Code:
    #!/bin/bash
    
    i="ping -c 1 www.google.com"
    
    if  $i < 0 ; then
    echo "you have a connection" > /dev/null
    else
    /sbin/dhcpcd -t 10 -d ath0 
    fi
    and if you run that as a cronjob it should be fine.
    Registered Linux User #371543!
    Get force-get May The Source Be With You
    /dev/null
    /dev/null2

Page 1 of 3 1 2 3 LastLast

Posting Permissions

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