How do I run a command at startup with systemd?

I need to run
# hdparm -B 255 /dev/sda
at startup. I used to do this in /etc/rc.local using initscrips. How do I do this using systemd?

Hi@ All!
I've tried to get power management work on my RTL8187SE Wireless LAN Controller.
# iwconfig wlan0 power on
works fine [edit] for some seconds, then connection is lost!
RTL8187SE is known for such issues due to 'too' aggressive HW-PM - i have been warned ;-)
[/edit]
but ...same procedure as last time... how to get it set automatic at boot?
Tried creating : /etc/udev/rules.d/wlan0_power_save.rules
with
ACTION=="add", SUBSYSTEM=="net", KERNEL=="wlan0", RUN+="/usr/sbin/iwconfig wlan0 power on"
which does not work cause 'iwconfig wlan0' seems to be executed while 'power on' produces an error.
The way given here depends on 'iw' - but 'iw' does not work due to missing 'nl80211'... *confused*
Any ideas?
renegat
Edit:
'iw' is the 'newer' set of wireless-tools - and does not support such old cards as mine.
Last edited by renegat (2013-02-16 09:43:35)

Similar Messages

  • How can one run OS commands from JSP's?

    Hi
    I figured out the perms problem I had, and running a java class that calls Runtime.exec() now works - apparently; in fact, it doesn't really run the OS command, but returns "OK".
    Anyone have an idea how to make it actually run?
    Thanks,
    Paulo

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Paulo Rodrigues ([email protected]):
    Hi
    I figured out the perms problem I had, and running a java class that calls Runtime.exec() now works - apparently; in fact, it doesn't really run the OS command, but returns "OK".
    Anyone have an idea how to make it actually run?
    Thanks,
    Paulo<HR></BLOCKQUOTE>
    Hi Paulo, i use for that function the following code:
    // JDC Tech Tips February 15, 2000
    import java.io.*;
    import java.util.ArrayList;
    public class ExecDemo {
    static public String[] runCommand(String cmd)
    throws IOException {
    // set up list to capture command output lines
    ArrayList list = new ArrayList();
    // start command running
    Process proc = Runtime.getRuntime().exec(cmd);
    // get command's output stream and
    // put a buffered reader input stream on it
    InputStream istr = proc.getInputStream();
    BufferedReader br =
    new BufferedReader(new InputStreamReader(istr));
    // read output lines from command
    String str;
    while ((str = br.readLine()) != null)
    list.add(str);
    // wait for command to terminate
    try {
    proc.waitFor();
    catch (InterruptedException e) {
    System.err.println("process was interrupted");
    // check its exit value
    if (proc.exitValue() != 0)
    System.err.println("exit value was non-zero");
    // close stream
    br.close();
    // return list of strings to caller
    return (String[])list.toArray(new String[0]);
    public static void main(String args[]) throws IOException {
    try {
    // run a command
    String outlist[] = runCommand("rm ./dummy");
    // String outlist[] = runCommand("ls");
    // display its output
    for (int i = 0; i < outlist.length; i++)
    System.out.println(outlist);
    catch (IOException e) {
    System.err.println(e);
    Gert
    null

  • How to execute a Terminal command on startup?

    Greetings!
    Is it possible to automatically run a Terminal command at startup? (Specifically - a hwprefs command.)
    If so, could you please detail the steps involved?
    Many thanks!

    OK, then, that's pretty straight forward. You can write a small AppleScript like so:
    set mystring to do shell script "Insert Command String Here" with administrator privileges
    If you need to run the command with root permission then insert "sudo" before the command line, i.e., "sudo commandline". You will need to authenticate in this case so add "with adminstrator privileges" after the command string, i.e.,
    do shell script "sudo command string" with administrator privileges
    Compile the script as a run-only application then add the compiled script to your Login Items (Accounts preference pane.)
    Note that your command line will need the fully qualified path to the command.

  • How to we run the command  Create Sdmkitjar

    Hii Ep Gurus
                Pl let me know where do i run the command createsdnmkitjar
    Thanks In Advance
    Johny

    Hi Nithya
                  Our Basis People r Migrating the ep server so before doind it they need to pack all the sdm installed components u can refer the doc in the server sdm folder
    thanks
    johny

  • HOW DO I RUN DOS COMMANDS ON JAVA

    I SWEAR, I'LL PAY YA IF YOU HELP ME!!!
    Hi, this is the thing:
    have you ever run the "time" command on a DOS console?? if you have, you know that it shows the current time, and lets you set a new time.
    well, i need to make a java program to open a DOS console and execute the command, and making it able to write in information on the console so it sets a new time.
    MY PURPOSE IS NOT JUST WATCHING THE CURRENT TIME!! so please don't tell me to use System.getCurrentTimeMillis() or something like that; i explicitly need to run that DOS command. what's the Java code to do it??
    thank you!! and please attach your account # so you get a $50 deposit by the end of the week
    thank you!!

    Thanks a lot, you all guys, but i don't know what's with this thing.... it always throws an IOException, with the following exception stack trace:
    java.io.IOException: CreateProcess: temp.bat error=0
            at java.lang.Win32Process.create(Native Method)
            at java.lang.Win32Process.<init>(Win32Process.java:63)
            at java.lang.Runtime.execInternal(Native Method)
            at java.lang.Runtime.exec(Runtime.java:550)
            at java.lang.Runtime.exec(Runtime.java:416)
            at java.lang.Runtime.exec(Runtime.java:358)
            at java.lang.Runtime.exec(Runtime.java:322)
            at Tarea.main(Tarea.java:15)and it will come out the same shit over and over. The above case was thrown by the line Runtime.getRuntime().exec("temp.bat") where temp.bat is a file where the only thing written in it is the word "time". and you can change the string parameter of the method exec, and thats what will change in the stack trace above.
    I also tried "cmd", "command", and "command.com". With the last one, it opens the command.com application but it freezes and does nothing. With the other two, appears the same old shit from above.
    Please help me!!
    Thank you...

  • [Solved] Running mpd as user mpd with systemd without using mpd.conf

    Maybe this is tivial, but I searched about an hour without any results. I want to run mpd as user mpd. I cant use the mpd config file since mpd set the UID and GID explicitely resulting in mpd not having the necessary supplementary groups to access the locally shared music on my pc. Well I tried to run mpd with systemd by
    # systemctl start mpd
    and  the systemd contains the user mpd
    $ cat /etc/systemd/system/default.target.wants/mpd.service
    [Unit]
    Description=Music Player Daemon
    After=network.target sound.target
    [Service]
    User=mpd
    ExecStart=/usr/bin/mpd --no-daemon
    # allow MPD to use real-time priority 50
    LimitRTPRIO=50
    LimitRTTIME=-1
    # move MPD to a top-level cgroup, as real-time budget assignment fails
    # in cgroup /system/mpd.service, because /system has a zero real-time
    # budget; see
    # http://www.freedesktop.org/wiki/Software/systemd/MyServiceCantGetRealtime/
    ControlGroup=cpu:/mpd
    # assign a real-time budget
    ControlGroupAttribute=cpu.rt_runtime_us 500000
    [Install]
    WantedBy=default.target
    but it did not run as mpd.
    Well how can I run mpd as mpd? Is there a way to do it like with dropbox: dropbox@<user>.service
    Last edited by manuelschneid3r (2015-03-25 12:52:52)

    Glad you solved it. Was just typing a response and I'll still add two remarks:
    The ps|grep output showed that you run grep as root, not mpd itself (which won't have a space in the command -- the second time it only worked because the mpd group is preceded by a space).
    It sounds like it took you a while to find the drop-in configuration snippet in the mpd.service.d directory. These drop-in are shown in `systemctl status`, which is something you'd normally check in situations like these, and that might help to discover them more quickly.
    Last edited by Raynman (2015-03-25 12:58:36)

  • Brightness control at startup with systemd

    I finally upgraded to systemd (I know... a bit later than I should have), and the transistion has been smooth, except for enabling brightness controll at boot.
    I currently have a bit of a hack working to enable brightness control on my Dell XPS 13 ultrabook. I have two backlight interfaces (/sys/class/backlight/intel_backlight and /sys/class/backlight/acpi_video0), and I have found that the only way to alter my screen brightness is to set the intel_backlight brightness value to 0 and then alter the brightness file under the acpi_video0 interface. I must always write the 0 to the intel_backlight/brightness file, even if it already contains 0, to enable brightness control through acpi_video0.
    I had had this code in my rc.local previously, and it worked exactly as I needed to enable brightness control:
    #!/bin/bash
    # set intel interface to 0, allowing acpi interface to take precedence
    echo 0 > /sys/class/backlight/intel_backlight/brightness
    # set the permissions of the acpi brightness file for video group (me) regular user modification
    chgrp video /sys/class/backlight/acpi_video0/brightness
    chmod 664 /sys/class/backlight/acpi_video0/brightness
    # initialize brightness to a low level
    echo 3 > /sys/class/backlight/acpi_video0/brightness
    exit 0
    Currently when I run this script normally it grants me the brightness control I desire through the modification of /sys/class/backlight/acpi_video0/brightness. I have made this script into a systemd service initiated at startup, with the service file below:
    [Unit]
    Description=Brightness Control Initialization
    [Service]
    Type=oneshot
    ExecStart=/usr/lib/systemd/scripts/bright_init
    RemainAfterExit=yes
    [Install]
    WantedBy=multi-user.target
    My issue is that although the service is initiated at startup without error, my brightness control does not function like it does when I run the script manually myself. I have verified that systemd considers the service to have run successfully after startup, and I have also enabled both the multi-user.target and above service.
    My questions are twofold:
    1. Is there a better way to allow brightness control other than the somewhat hacky method of zeroing the /sys/class/backlight/intel_backlight/brightness file with the above script?
    2. And does anyone have an idea as to why my service doesn't work, even though I can run the script after startup and it functions as I desire?
    Last edited by tyler.heck (2012-11-16 01:45:46)

    It is interesting to see that this is working for you. I had to add OWNER="root" to the rule. Otherwise when testing the rule with `udevadm test` I always recieved a permission denied error. But even with OWNER="root" Udev did not actually write the ATTR{brightness}="2" into the file.
    Manually doing that by echo 2 > ... works well. I searched a bit on this topic and found a thread on the Gentoo forum where they say that it is not wise to use Udev for writing anything to /sys. Instead you should use Udev to run a script that does that:
    [orschiro@thinkpad ~]$ cat /etc/udev/rules.d/50-powersave.rules
    SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/home/orschiro/Scripts/powersaving battery"
    SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/home/orschiro/Scripts/powersaving AC"
    [orschiro@thinkpad ~]$ cat /usr/local/bin/powersaving
    #!/bin/sh
    case $1 in
    battery)
    echo "Running powersaving on AC in 3 seconds"
    sleep 3
    # screen power saving"
    echo 200000 > /sys/class/backlight/intel_backlight/brightness
    AC)
    echo "Running powersaving on battery in 3 seconds"
    sleep 3
    # screen power saving
    echo 4270725 > /sys/class/backlight/intel_backlight/brightness
    esac
    Last edited by orschiro (2013-03-01 15:29:02)

  • How to cancel filesystem check at boot time with systemd

    Hello,
    while booting, when the filesystem is checked and it takes too long, it was possible with initscripts to press ctrl^c to cancel the check and postpone it to the next boot. How this can be done with systemd?

    http://kernelnewbies.org/Ext4#head-9a25 … 1279bd2b00 would lead me to think that fsck on converted ext4 should be as fast as on a regular ext4, unless http://kernelnewbies.org/Ext4#head-e7f9 … 68c012655c you're using a compatibility mode by mounting the converted fs as ext3.
    https://wiki.archlinux.org/index.php/Ex … to_extents should take care of old, pre-migration data.
    Admittedly, I may be reading into this too much, this is mostly guesswork on my part and you seem to know much more about the filesystems than I do :-)

  • How would I run these commands?

    I'd like to derive version metadata on specific applications AND I'd like to extract the Mac OS Build while I'm at it.  Each of the following commands works great individually but to run the entire batch at once and have it echo back a simple report do I need to create a script?  How can I tiew these together in a Terminal command?  Thanks.
    mdls -name kMDItemVersion /Applications/Microsoft\ Office\ 2011/Microsoft\ Excel.app
    mdls -name kMDItemVersion /Applications/Adobe\ Reader.app
    mdls -name kMDItemVersion /Applications/Safari.app
    mdls -name kMDItemVersion /Applications/Google\ Chrome.app
    mdls -name kMDItemVersion /Applications/Adobe\ Acrobat\ X\ Pro/Adobe\ Acrobat\ Pro.app
    SW_VERS

    Open the AppleScript Editor in the /Applications/Utilities/ folder and run:
    set the_versions to (do shell script "mdls -name kMDItemVersion /Applications/Microsoft\\ Office\\ 2011/Microsoft\\ Excel.app")
    set the_versions to the_versions & return & (do shell script "mdls -name kMDItemVersion /Applications/Adobe\\ Reader.app")
    set the_versions to the_versions & return & (do shell script "mdls -name kMDItemVersion /Applications/Safari.app")
    set the_versions to the_versions & return & (do shell script "mdls -name kMDItemVersion /Applications/Google\\ Chrome.app")
    set the_versions to the_versions & return & (do shell script "mdls -name kMDItemVersion /Applications/Adobe\\ Acrobat\\ X\\ Pro/Adobe\\ Acrobat\\ Pro.app")
    (107655)

  • Please help How can i run Os commands thru Java programs

    Hey,
    I want to stop and restart the linux server thru java program.Is it possible to run the os commands thru java program.
    I had it thru Runtime.getRuntime().exec("*.exe");
    it only runs the exe files.How can run files other than exe files like .bat,com ans shell commands..Any body knows please help with the code..or mail to this address
    [email protected]
    thankyou,
    regards,
    j.mouli

    What about "start command.com /C execute.bat", or using the overload that takes a String[] as argument?
    What if you use the the full path of execute.bat?
    What error code do you get?
    And what comes th linux, I'm not sure... you'll need a shell interpreter there too, me thinks. (never had to run anything with runtime.exec on linux). Check the man pages if csh, bash, ksh, or what ever shell you like.

  • How can you run a command with elevated rights on a remote server with invoke-command ?

    I am trying to run a script on a remote server with invoke-command.  The script is starting and is running fine, but the problem is that it should be running with elevated rights on the remote server.  On the server where I start the invoke-command, my account has the necessary rights.
    The server were I launch the invoke-command is a W2K8 R2.  The remote box is a W2K3 with powershell v2.0 installed.
    When I launch the script on the remote-box from the command line, I don't get the access denied's.
    Is there a way to do this ?
    Thanks in advance

    The script that I want to run is to install the windows updates.  I get an access denied on the download of the updates.
    When I execute the script on an W2K8 box, (not remotely) and I run it with non-elevated rights, I get the same error.
    The script is running fine when it is launched on W2K3 box locally with a domain account that has local admin rights, or on a W2K8 R2 server with a domain account that has local admin rights, but with elevated rights.
    Thanks in advance for your help.
    #=== start script ====
    param($installOption="TESTINSTALL",$rebootOption="NOREBOOT")
    Function Show-Help
    Write-Host ""
    Write-Host "SCRIPT: $scriptName <installOption> <RebootOption>"
    Write-Host ""
    Write-Host "DESCRIPTION: Installatie van WSUS updates op de lokale server"
    Write-Host ""
    Write-Host "PARAMETERS"
    Write-Host " -installOption <[INSTALL|TESTINSTALL]>"
    Write-Host " -rebootOption <[REBOOT|NOREBOOT|REBOOT_IF_UPDATED]>"
    Write-Host ""
    Write-Host "EXAMPLE:"
    Write-Host "$ScriptName -installOption INSTALL -rebootOption REBOOT_IF_UPDATED"
    Write-Host "$ScriptNAme INSTALL NOREBOOT"
    Write-Host ""
    Write-Host "Indien beide parameter weggelaten worden zijn de defaultwaarden :"
    Write-Host " installOption=TESTINSTALL "
    Write-Host " RebootOption=NOREBOOT"
    Write-Host ""
    Exit
    #Include alle globale variablen
    $CEIF_WIN_PATH = (get-content env:CEIF_WIN_PATH)
    $includeFile=$CEIF_WIN_PATH + "\Scripts\include_win.ps1"
    . $includeFile
    #initialiseer error count
    $errcnt=0
    $scriptName=$MyInvocation.MyCommand.Name
    #argumenten controleren
    $arrInstallOption= "TESTINSTALL", "INSTALL" # Mandatory variable with predefined values
    If (!($arrInstallOption –contains $installOption)){ Show-Help }
    $arrRebootOption = "REBOOT", "NOREBOOT","REBOOT_IF_UPDATED" # Mandatory variable with predefined values
    If (!($arrRebootOption –contains $rebootOption)){ Show-Help }
    #Logfile opbouwen
    $logfile = get-logfileName($MyInvocation.MyCommand.Name)
    Log-scriptStart $MyInvocation.MyCommand.Name $logfile
    function Get-WIAStatusValue($value)
    switch -exact ($value)
    0 {"NotStarted"}
    1 {"InProgress"}
    2 {"Succeeded"}
    3 {"SucceededWithErrors"}
    4 {"Failed"}
    5 {"Aborted"}
    function boot-server()
    if ($installOption -eq "TESTINSTALL")
    logger "TESTINSTALL : - Reboot local Server" $logfile
    else
    logger " - Reboot local Server" $logfile
    $thisServer = gwmi win32_operatingsystem
    $thisServer.psbase.Scope.Options.EnablePrivileges = $true
    $thisServer.Reboot()
    $logmsg="Install option = " + $installOption + ", RebootOption = $rebootOption"
    logger "$logmsg" $logfile
    logger "" $logfile
    logger " - Creating WU COM object" $logfile
    $UpdateSession = New-Object -ComObject Microsoft.Update.Session
    $UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
    logger " - Searching for Updates" $logfile
    $SearchResult = $UpdateSearcher.Search("IsAssigned=1 and IsHidden=0 and IsInstalled=0")
    logger " - Found [$($SearchResult.Updates.count)] Updates to Download and install" $logfile
    $Updates=$($SearchResult.Updates.count)
    logger "" $logfile
    foreach($Update in $SearchResult.Updates)
    if ($Update.EulaAccepted -eq 0)
    $Update.AcceptEula()
    # Add Update to Collection
    $UpdatesCollection = New-Object -ComObject Microsoft.Update.UpdateColl
    $UpdatesCollection.Add($Update) | out-null
    if ($installOption -eq "TESTINSTALL")
    else
    # Download
    logger " + Downloading Update $($Update.Title)" $logfile
    $UpdatesDownloader = $UpdateSession.CreateUpdateDownloader()
    $UpdatesDownloader.Updates = $UpdatesCollection
    $DownloadResult = $UpdatesDownloader.Download()
    $Message = " - Download {0}" -f (Get-WIAStatusValue $DownloadResult.ResultCode)
    if ($DownloadResult.ResultCode -eq 4 )
    { $errcnt = 1 }
    logger $message $logfile
    # Install
    logger " - Installing Update" $logfile
    $UpdatesInstaller = $UpdateSession.CreateUpdateInstaller()
    $UpdatesInstaller.Updates = $UpdatesCollection
    $InstallResult = $UpdatesInstaller.Install()
    $Message = " - Install {0}" -f (Get-WIAStatusValue $InstallResult.ResultCode)
    if ($InstallResult.ResultCode -eq 4 )
    { $errcnt = 1 }
    logger $message $logfile
    logger "" $logfile
    #Indien er een fout gebeurde tijdens download/installatie -> stuur mail naar windowsteam
    if ( $errcnt -gt 0 )
    logger " - Fout tijdens de uitvoering van script -> send mail" $logfile
    $mailSubject=$MyInvocation.MyCommand.Name
    $msg = new-object Net.Mail.MailMessage
    $att = new-object Net.Mail.Attachment($logfile)
    $smtp = new-object Net.Mail.SmtpClient($smtpServer)
    $msg.From = $mailFrom
    $msg.To.Add($mailTo)
    $msg.Subject = $mailSubject
    $msg.Body = “Meer details in attachement”
    $msg.Attachments.Add($att)
    $smtp.Send($msg)
    #Moet de server herstart worden ?
    if ($rebootOption -eq "REBOOT_IF_UPDATED" )
    if ($Updates -gt 0)
    #Reboot the server when updates are installed
    boot-server
    elseif ($rebootOption -eq "REBOOT")
    #reboot the server always
    boot-server
    else
    #Do not reboot the server
    logger "Do not reboot the server" $logfile
    Log-scriptEnd $MyInvocation.MyCommand.Name $logfile
    exit 0

  • How can I run different commands in the same system exec window?

    I want to open a window (cygwin) on my Xp machine and sent commands within that window. I then have to monitor what the responses are coming back into the window that was launched. Any ideas on how to do this? I have been playing with the system exec VI but can't seem to get it to do what I want. Any help would be appreciated. Thanks - Troy

    Hello,
    Have you tried setting the wait until completion to true on the System Exec VI?  If so, the LabVIEW documentation claims that the parameter "standard output returns information from the program you called if wait until completion is TRUE. If wait until completion is FALSE, System Exec returns an empty string."
    Could this be the answer to the problem of getting the data returned?
    I hope this helps!
    Best Regards,
    JLS
    Best,
    JLS
    Sixclear

  • How can i run javac command in a Servlet?

    I wanna use javac command in a Servlet ,
    but it can not load the tomcat's lib.
    What can i do?

    Try out. But Iam not sure.
    Runtime.getRuntime("Cmd.Exe"). This wiil open the dos prompt.
    Create ouput stream and write in to it.Try to execute key.
    To invoke the enter key , use ascii value of the enter key

  • How to compile & run using command prompt

    Hi all,
    I have a java application consisting of 3 packages & a jar file in the following hierarchy:
    -Project
    -classes
    -src
    -package1
    -package2
    -package3
    -file.jar
    The main class exists in package2 and uses classes within file.jar
    I want the steps to compile and execute the project using command prompt in windows such that the generated classes will be saved in the classes directory
    Can anyone help?
    Thanx in advance

    Hey,
    If your source(*.java) files are in src folder and ur currnet directory is project
    and you want all your class files to be classes folder then you can try this :
    c:\project>javac -cp src\file.jar -d classes\ src\*.javaAssuming that your file.jar file is in src folder.
    The above command will set the classpath to src\file.jar (-cp src\file.jar)
    -d classes\ - will generate all your class files with package hierarchy if any into classes directory.
    src\*.java - specifies the files to be compiled.
    Hope this helps.

  • I have all my music on a external HD. How can I run iTunes on my laptop with out my EHD connected? when I open iTunes I get: Afolder containing "iTunes Library" cannot be found, and is required. Please chose or create a new iTunes library.

    It also tells me Choose iTunes Library
    iTunes needs a library to continue, you may choose an existing library or create a new one.
    I have all my music on an external hard drive (ehd) but would like to run itunes with out conecting my ehd. How can i do this? I'm

    You need the entire libary on the external, not just media.
    What are the iTunes library files? - http://support.apple.com/kb/HT1660
    More on iTunes library files and what they do - http://en.wikipedia.org/wiki/ITunes#Media_management
    What are all those iTunes files? - http://www.macworld.com/article/139974/2009/04/itunes_files.html
    Where are my iTunes files located? - http://support.apple.com/kb/ht1391
    iTunes 9 [and later]: Understanding iTunes Media Organization - http://support.apple.com/kb/ht3847
    Image of folder structure and explanation of different iTunes versions (turingtest2 post) - https://discussions.apple.com/message/13025536 and https://discussions.apple.com/message/17457605
    Once you get a complete iTunes folder on the external drive, start iTunes with the option/alt key held down and select the iTunes Library.itl file on the external drive.  You will also need to do this with your main computer or the libraries will become unsynchronized.
    Alternatively you can make a separate library using the same media on the second computer. Start as you have been doing, let iTunes create a new, blank library file which will be on hte internal drive, set the media folder location in preferences to be the one on the external drive, then add the files to the new iTunes library. Unless you are a super-organized individual, or you don't care if your libraries do not have the same content, you are better off using a single library file that is on the external, not setting up separate library files.

Maybe you are looking for