Announcement

Collapse
No announcement yet.

How do you create and run scripts?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How do you create and run scripts?

    I've noticed that the broadband speed on my laptop drops significantly when on battery power, to resolve this I need to run the following command in Terminal/Konsole:

    sudo iwconfig eth0 power off

    However I need to do this every time I switch on. I've noticed in the power management settings though that you can set each power management profile to run a script. Only problem is I don't know how to create one, so any advice would be greatly appreciated.
    Kubuntu 15.10

    #2
    Re: How do you create and run scripts?

    In linux, scripts are basically just text files with the proper permissions and structure.

    Likely, just use kate to create a textfile called noeth0 or whatever in your home directory, add your command to it, change it to executable, and add it to your power profile. The sudo issue might come up. I would guess that you'd leave sudo out of the text file and hope the power management calls the script with su permissions. I haven't tried it.

    Please Read Me

    Comment


      #3
      Re: How do you create and run scripts?

      Thanks for the help, I thought that was the way to go just wasn't 100% sure.

      However nothing appears to happen, I've tried the script with and without the 'sudo' element but nothing, I would have expected at least some error message. Not sure if the problem is with the script or with trying to get power manager to run it.
      Kubuntu 15.10

      Comment


        #4
        Re: How do you create and run scripts?

        Couple things here.

        An *interactive* script would need to be run in a terminal window. I think your script would look more like this -

        #!/bin/bash

        konsole -e sudo iwconfig eth0 power off

        Additionally, the default terminal emulator in X is xterm - if you wanted your script to work no matter what DE or window manager you used you'd do it this way -

        #!/bin/bash

        xterm -e sudo iwconfig eth0 power off

        but - at least on my machine using iwconfig on a wired interface doesn't work. I get

        wizard@wizard-netbook:~$ sudo iwconfig eth0 power off
        [sudo] password for wizard:
        Error for wireless request "Set Power Management" (8B2C) :
        SET failed on device eth0 ; Operation not supported.
        wizard@wizard-netbook:~$

        Last, I'm not clear on why an active wired interface would affect the speed of a wireless interface. I won't debate that's what you're seeing, I'm just saying I don't understand why that'd be the case.

        cheers -
        we see things not as they are, but as we are.
        -- anais nin

        Comment


          #5
          Re: How do you create and run scripts?

          Hi,

          That's strange, when I tried this last night I checked the network manager via the icon on the panel and I could of swore that under 'System Name' it had my WLAN interface down as eth0 but after reading what you just said i checked again and now it says eth1, I must have been more tired than i thought last night.

          Thanks for the advice, I shall try again, hopefully with the correct script this time.
          Kubuntu 15.10

          Comment


            #6
            Re: How do you create and run scripts?

            Excellent,!

            Thanks for the advice Wizard10000, I tried the script as you suggested and changed 'eth0' to 'eth1' and it works fine, obviously with the exception that I need to enter my password into the terminal when I run it, I'm guessing there's no way round that though.

            Kubuntu 15.10

            Comment


              #7
              Re: How do you create and run scripts?

              Originally posted by kri5
              Excellent,!

              Thanks for the advice Wizard10000, I tried the script as you suggested and changed 'eth0' to 'eth1' and it works fine, obviously with the exception that I need to enter my password into the terminal when I run it, I'm guessing there's no way round that though.
              I'm afraid not - you've gotta be root to configure a network interface.

              Glad it worked for you, though
              we see things not as they are, but as we are.
              -- anais nin

              Comment


                #8
                Re: How do you create and run scripts?

                wiz, could the script be added to sudoers with NOPASSWD flag?

                Please Read Me

                Comment


                  #9
                  Re: How do you create and run scripts?

                  Originally posted by oshunluvr
                  wiz, could the script be added to sudoers with NOPASSWD flag?
                  Possibly - I haven't tried it but it's worth a shot.

                  Circumventing security protocols generally gives me the heebie-jeebies. A lot of people are fine with it, but I generally won't recommend it as a solution. OP may be just fine with it, though.
                  we see things not as they are, but as we are.
                  -- anais nin

                  Comment


                    #10
                    Re: How do you create and run scripts?

                    It's sounds like it's getting a bit more complex some of these commands are a bit over my head, I'm probably better of sticking to entering my password, at least until I know what I'm doing.

                    Some more experience of the command line is required I think.
                    Kubuntu 15.10

                    Comment


                      #11
                      Re: How do you create and run scripts?

                      "Hooking ?"


                      If you need the root rights to execute commands before the KDE is starting you could add the commads to the existing scripts.

                      The /etc/kde4/kdm/Xsetup is:
                      (https://wiki.ubuntu.com/X/Config/Resolution)
                      Both KDM and GDM have startup scripts that are executed when X is initiated. For GDM, these are in /etc/gdm/ , while for KDM this is done at /etc/kde4/kdm/Xsetup. In either case, you can paste in an xrandr command line string into one of these scripts....
                      The /etc/kde4/kdm/Xsetup:
                      Code:
                      #! /bin/sh
                      # Xsetup - run as root before the login dialog appears
                      
                      #xconsole -geometry 480x130-0-0 -notify -verbose -fn fixed -exitOnFail -file /dev/xconsole &
                      
                      /sbin/initctl -q emit login-session-start DISPLAY_MANAGER=kdm

                      Maybe in this case:
                      Code:
                      #! /bin/sh
                      # Xsetup - run as root before the login dialog appears
                      
                      #xconsole -geometry 480x130-0-0 -notify -verbose -fn fixed -exitOnFail -file /dev/xconsole &
                      
                      # disable wireless network power management.
                      iwconfig eth0 power off &
                      
                      /sbin/initctl -q emit login-session-start DISPLAY_MANAGER=kdm

                      Earlier > Topic: Capturing the images of the ksplash & kdm & ksplash again
                      (Using the Xsetup hook to capture the boot screens)
                      A good place to start: Topic: Top 20 Kubuntu FAQs & Answers
                      Searching FAQ's: Google Search 'FAQ from Kubuntuforums'

                      Comment

                      Working...
                      X