[solved] Running a command in background (bash script)

Salut,
as netcfg2 does not work with my wireless connection, I have to set up the connection manually. For not having to type in the commands every time, I created a bash script.
#!/bin/bash
iwconfig wlan0 mode managed essid mynetwork channel 6
ifconfig wlan0 up
wpa_supplicant -D wext -i wlan0 -c /etc/wpa_supplicant.conf -dddd &
dhcpd wlan0
This works fine till the wpa_supplicant line. wpa_supplicant is not started in the background (as I thought, the ampersand at the end of the line would.
So how can I get wpa_supplicant run in the background?
Thanks in advance,
Stefan
Last edited by vbtricks (2008-05-11 09:13:36)

Ramses de Norre wrote:How do you know it isn't? What exactly does happen?
The script does not return to the user-prompt. Is an ampersand at the end of the line the correct solution, or are you unsure yourself?
bender02 wrote:On thing is that even if it starts, it does take it a couple of seconds to connect, so it's probably not very good to run dhcpcd right after wpa_supplicant. Another thing is that you probably have a typo up there, shouldn't it be 'dhcpcd' instead of 'dhcpd'?
Well, as the wpa_supplication command is not really run in the background the script did never execute the dhcpcd command. After having solved the above, correcting the spell-mistake will be a smaller problem. Even calling the dhcpcd command myself would be no unworkable way, the open root-shell (as I have to use another as the one calling the script is blocked) is a far greater problem...

Similar Messages

  • [SOLVED] Running sudo command to be executed on dmenu

    I'm using "sudo grub-reboot 2". What is the best way to run this command with dmenu, considering that sudo is necessary, without sacrificing security?
    Last edited by Quatro (2014-08-19 00:22:24)

    My dmenu power menu script looks like this.
    power_menu.sh
    #!/bin/bash
    # dmenu2 power menu
    OPT=$(echo -e "suspend\npoweroff\nreboot" | dmenu -f -h 28 -fn "Ubuntu Mono-12" -x 460 -y 370 -w 360 -nb black -nf white -sb white -sf black )
    case $OPT in
    suspend) sudo systemctl suspend ;;
    poweroff) sudo systemctl poweroff ;;
    reboot) sudo systemctl reboot ;;
    esac
    And the following file allows me to run those commands without being prompted for a password.
    /etc/sudoers.d/include
    slithery ALL=(ALL) NOPASSWD:/usr/bin/systemctl suspend
    slithery ALL=(ALL) NOPASSWD:/usr/bin/systemctl poweroff
    slithery ALL=(ALL) NOPASSWD:/usr/bin/systemctl reboot
    Just use these as an example and you should get what you're after.
    Last edited by slithery (2014-08-18 11:52:31)

  • [SOLVED] Running Two Commands at Boot

    I've tried adding to the Startup Manager in Gnome and since that didn't work, I tried adding to rc.local to no avail. The only way I can run these scripts is manually through the terminal. The commands are to enable wireless and compiz:
    wireless.sh
    sudo wicd -foe
    /usr/bin/wicd-client
    compiz.sh
    LIBGL_ALWAYS_INDIRECT=1 compiz --replace ccp & emerald --replace &
    Here's what I put in rc.local
    /etc/rc.local
    #!/bin/bash
    # /etc/rc.local: Local multi-user startup script.
    sh ~/Scripts/wireless.sh
    LIBGL_ALWAYS_INDIRECT=1 compiz --replace ccp & emerald --replace &
    Last edited by vahnx (2010-08-31 05:30:34)

    They didn't work in rc.local since that loads before you log in (I think right after it finishes loading all the daemons). You'll need to run the full path (not using ~). Also, that won't help you with running GUI apps (like compiz, or the wicd tray icon). Also, if your sudo asks for a password that's probably why it doesn't work from Gnome startup (not sure about the compiz one, maybe try putting env before the command like "env LIBGL_ALWAYS_INDIRECT=1 compiz --replace ccp && emerald --replace" And oh yeah, to run another command it's "&&", not "&" (you can also use a
    Last edited by doorknob60 (2010-08-31 05:21:31)

  • [SOLVED] Conky Mail Notification using a Bash Script

    Hi there, I have conky piped into a dzen panel, and I'm trying to get conky to echo my unread mail count whenever the # is >0. It's just not working for me, and I was wondering what I did incorrectly.
    I have the 3 following files.
    ~/.conkyrc
    background yes
    out_to_console yes
    out_to_x no
    update_interval 1
    TEXT
    ${execi 60 /home/nil/mail-notify}
    ~/mail-notify
    #! /bin/bash
    gmail=$(python /home/nil/gmail.py)
    if [ $gmail -gt 0 ]; then
    echo "$gmail"
    fi
    ~/gmail.py
    #!/usr/bin/env python
    # This is a script that checkes the gmail unread count.
    from urllib.request import FancyURLopener
    username = 'myusername'
    password = 'mypasswd'
    url = 'https://%s:%[email protected]/mail/feed/atom' % (username, password)
    opener = FancyURLopener()
    page = opener.open(url)
    contents = page.read().decode('utf-8')
    ifrom = contents.index('<fullcount>') + 11
    ito = contents.index('</fullcount>')
    unread = contents[ifrom:ito]
    print(unread)
    gmail.py was taken from the archwiki page, and I've confirmed it to be working (I censored my user name and password here). What gmail.py does is output an integer representing your unread mail count.
    Similarly, Conky's code and the mail-notify script run fine. If I rewrite mail-notify's conditional to be "if [ 1 -gt 0 ]; then", then it will successfully output the unread mail count. Hence the problem lies in the scripting of the if condition. mail-notify should run gmail.py, if the output count is >0, then it should echo that number. Else it does nothing. Any help is appreciated!
    Last edited by nil (2013-08-19 23:40:14)

    jasonwryan wrote:Presumably the script is called gmail.py, not gmail1.py?
    Oops, sorry, that was a typo when writing up this post.

  • [SOLVED] FFMPEG appears to be trashing bash script variables

    Hi,
    I have a directory containg MP4 files which were downloaded via youtube-dl upon which I want to extract audio using FFMPEG.
    I am using the usual find/while/read/do/done loop to process each file individually. The files were downloaded using Youtube-dl (invoked with --restrict-filenames) so the youtube video ID is recorded within the filename which can then be used to obtain the video title (ie to tag the audio with once extracted, ie ID3).
    Without FFMPEG the loop works as expected as can be seen when using echo, but as soon as I introduce FFMPEG into the loop, no such file or directory errors are reported because the filenames passed to FFMPEG are nonsense and appear to have been trashed, for instance, characters are stripped from the start or end of the filename.
    find . -name '*.mp4' | while read FILE
    do
    FNAME=${FILE%.mp4}
    FID=${FNAME: -11}
    FTITLE=${FNAME%-$FID}
    TITLE=$(youtube-dl --get-title $FID)
    # MP3="${FNAME}.mp3"
    AAC="${FNAME}.aac"
    ffmpeg -i $FILE -vn -acodec copy $AAC
    done
    Frequently green text like so reams down the terminal:
    stream #1:
    keyframe=1
    duration=0.023
    dts=355.033 pts=355.033
    size=252
    Swiftly followed by:
    00000000 21 0a 4f ff ff e0 3f fe a2 c6 b1 41 31 a0 88 41 !.O...?....A1..A
    00000010 28 3e 00 03 d2 15 25 4a 92 17 40 0b e4 f5 4c e5 (>....%[email protected].
    00000020 af 56 45 aa 31 0c eb 87 45 ac 26 54 8a ed c9 b4 .VE.1...E.&T....
    00000030 94 98 ca a8 03 34 aa bf 04 51 38 12 c9 43 80 62 .....4...Q8..C.b
    00000040 5b 16 94 99 20 18 9e cd 55 d0 6c 15 38 13 ce cc [... ...U.l.8...
    00000050 d4 2e 80 3b 10 e9 07 70 bc 23 8c 8c 84 96 8a 38 ...;...p.#.....8
    00000060 29 63 8d 87 75 5e 66 dc fa de 7f 4e 70 b2 44 09 )c..u^f....Np.D.
    00000070 39 c7 30 50 78 2b 6a b0 48 90 ba c4 14 c4 41 5c 9.0Px+j.H.....A\
    00000080 b6 3c 64 38 4d 92 3a b6 d1 01 d3 99 86 d5 54 23 .<d8M.:.......T#
    00000090 2a c4 13 49 61 50 b7 d0 3c 1e 2b 4b 90 c4 32 ae *..IaP..<.+K..2.
    000000a0 bc 6b 57 a6 de df 19 53 8e 38 66 d1 c4 fc a4 d5 .kW....S.8f.....
    000000b0 f9 6f a9 2d 20 6c eb 29 1e 1a ef 96 a6 84 82 63 .o.- l.).......c
    000000c0 0a cc 75 82 14 b4 08 09 fa 11 b8 0d e7 11 80 84 ..u.............
    000000d0 20 31 18 00 05 2a 54 af 46 ac 08 79 b9 a8 11 70 1...*T.F..y...p
    000000e0 f5 c0 2f 88 4b 27 7c a4 fd f9 f1 e4 77 53 c5 4a ../.K'|.....wS.J
    000000f0 d7 74 d1 02 80 46 40 08 16 a1 e7 .t...F@....
    It doesn't matter if the filenames originate from find or redirected from the contents of a text file. Anyone have any suggestions for workarounds?
    Last edited by jwm-art (2014-05-27 21:39:39)

    Self contained example:
    #!/bin/bash
    while read URL
    do
    echo -n "Downloading video from ${URL}... "
    youtube-dl --restrict-filenames "${URL}" --quiet
    if test $? -eq 0; then
    echo "Ok"
    else
    echo "FAIL"
    echo "Aborting..."
    exit
    fi
    done <<YT_URLS
    https://www.youtube.com/watch?v=XqdYnxv01yM
    https://www.youtube.com/watch?v=lX_o5t2YoUE
    https://www.youtube.com/watch?v=V9sI6VEDE5M
    YT_URLS
    find . -name '*.mp4' | while read -r FILE
    do
    echo "-----------------------------------------"
    echo -n "Converting ${FILE} to MP3... "
    MP3="${FILE%.mp4}.mp3"
    echo "${MP3}"
    ffmpeg -loglevel warning -y -i "${FILE}" "${MP3}"
    if test $? -eq 0; then
    echo "Ok"
    else
    echo "FAIL"
    echo "Abortingm..."
    exit
    fi
    echo
    done
    Here's the output on my system:
    $ ../ffmpeg_test
    Downloading video from https://www.youtube.com/watch?v=XqdYnxv01yM... Ok
    Downloading video from https://www.youtube.com/watch?v=lX_o5t2YoUE... Ok
    Downloading video from https://www.youtube.com/watch?v=V9sI6VEDE5M... Ok
    Converting ./Rabbit_City_White_Lable_-_Beyond_Control-lX_o5t2YoUE.mp4 to MP3... ./Rabbit_City_White_Lable_-_Beyond_Control-lX_o5t2YoUE.mp3
    Enter command: <target>|all <time>|-1 <command>[ <argument>]
    Parse error, at least 3 arguments were expected, only 1 given in string 'osmo_Dibs_-_Xultation-V9sI6VEDE5M.mp4'
    debug=1
    debug=2 1984kB time=00:02:06.95 bitrate= 128.0kbits/s
    error parsing debug value
    debug=0
    [output stream 0:0 @ 0xd90b60] EOF on sink link output stream 0:0:default.
    No more output streams to write to, finishing.
    [libmp3lame @ 0xc71de0] Trying to remove 815 more samples than there are in the queue
    size= 6971kB time=00:07:26.12 bitrate= 128.0kbits/s
    video:0kB audio:6971kB subtitle:0 data:0 global headers:0kB muxing overhead 0.004483%
    19212 frames successfully decoded, 0 decoding errors
    [AVIOContext @ 0xd9ff60] Statistics: 2 seeks, 17081 writeouts
    [AVIOContext @ 0xc77200] Statistics: 7082450 bytes read, 176 seeks
    Ok
    The first MP4 file found is converted, but alongside strange unexplained output, and then it just stops. In the first iteration of the second loop how does FFMPEG get hold of the second filename (incomplete, missing first character)? What is the "Enter command" all about? Its all very weird.
    Last edited by jwm-art (2014-05-27 20:17:57)

  • Bash script: Loop command,

    Hi all,
    I need a bit of help looping a command on a bash script,
    please see below the command I need to loop:
    ffmpeg -s 2720x1024 -r 25 -f x11grab -i :0.0 -acodec libmp3lame -ab 128k -vcodec mpeg4 -sameq -y -t 60 /media/z/.cam/screen/screen_`date +%F_%T`.avi
    So basically I record my screen for a period of 1 minutes and the process once done need to restart.
    I have search on how to loop the command but I must admit it seem rather complicated, so for the time being I added && at the end and paste the command a lot...
    Any help would be appreciated,
    Many thanks,
    Regards

    sweetthdevil wrote:ffmpeg -s 2720x1024 -r 25 -f x11grab -i :0.0 -acodec libmp3lame -ab 128k -vcodec mpeg4 -sameq -y -t 60 /media/z/.cam/screen/screen_`date +%F_%T`.avi
    I recommend using the FFmpeg commands shown here:
    How to do Proper Screencasts on Linux Using FFmpeg
    It's a well-written guide and the author, verb3k, keeps it up to date which is essential when working with FFmpeg.  Compared to your command the output will probably look better. The command from the guide will also probably be closer to your requested frame rate because the lossless output should be easier for the CPU to deal with and the command utilizes the -threads option.  Lastly, the -sameq option should not be used. The documentation is misleading and should read something like, "use same quantizer as source" instead of "use same video quality as source". Use of the same quantizer does not mean same quality, and this option especially should not be used when the source and output formats do not share the same quantizer scale.
    Last edited by DrZaius (2011-03-27 00:31:46)

  • Run Unix command / Run Unix shell script from Forms9i

    Hi,
    I have a requirement to run Unix command and Unix shell scripts from Forms9i.
    I know HOST command cannot be used directly. I also know we can create some JAVA stored procedure to perform the task, but I don't want to create any JAVA stored procedure as there are some security concerns.
    Please point me towards any other way to achieve the same.
    I would really appreciate your help.
    Thanks,
    Kumar

    There is no reason why HOST can't be used. This is what it is for. As for using Java, it is not a stored procedure that you would be using, it would be imported Java (imported into the form).
    The best way to use the HOST command is to call a script (.sh) rather than calling a Unix command directly. This is because HOST will not pick up environment variables set at the system level. So the script would first need to set the necessary environment variables then call the desired commands.

  • Sending email using bash script

    Hello:
    I am working on writing a bash script to notify one or more users by email of certain events. Run from the Terminal command line, and having the script "echo" text of (what would be) a form letter with in-line variable expansion (i.e., ${VARIABLE}), all seems to work as anticipated. Eventually, I want cron to launch this shell script, and send an email to an "on-subnet" user (I have postfix enabled on my Mac, and there are multiple local user accounts).
    I found some stuff on the web about sending mail from bash scripts, and so I made a small little test script, that reads like this:
    #!/bin/bash
    VARIABLE[1]="The 12,345 quick brown foxes "
    VARIABLE[2]="jumped over the 67,890 lazy dogs."
    mail -s "a test email" jv << EOF
    This is a test:
    ${VARIABLE[1]}
    ${VARIABLE[2]}
    This is the last line of the test message.
    EOF
    echo "script completed"
    It worked... almost... It sent a local email to my postfix mail account that read like this:
    This is a test:
    The 12,345 quick brown foxes
    jumped over the 67,890 lazy dogs.
    This is the last line of the test message.
    EOF
    echo "script completed"
    So, I have two questions. First, the easy one (I hope):
    How do I delimit the end of the text, that I want to be the message body of the email, from portions of the script that follow said email text?
    Next question is a little more involved. You know how, in Mail.app, if you go to Mail Preferences>Accounts>Account Information, you can put multiple email addresses, comma-delimited, in the "Email Address" field? So, if a person entered "[email protected], [email protected], [email protected]" in this field, then, even though (s)he may be at home, and using their home ISP's mail server, (s)he could send an email apparently from either their home, work, or school email address. Of course, the mail headers clearly would show it came from and through their home machine and home ISP, but it would be displayed in the recipient's Mail client viewer as having come from one of [email protected], [email protected], or [email protected].
    I'd like to do something similar here, whereby the email (that is being sent to one or more local users' postfix account on my computer) would apparently be sent from "watchdog@localhost" rather than from "jv@localhost" like it seems to do by default. Whatever account the script is run from (or presumbably, whose cron tab is launching the script) is what the "From" address is set to.
    I'd rather not create an additional mail account, because I am using Mac OS X built-in accounts for the postfix mailboxes (I don't want to have to maintain a plaintext username:password file in postfix, and I don't want to create an additional user account on the computer).
    So, is there a way to specify an alternate "From" username when invoking the mail -s ${SUBJECT} ${RECIPIENT} command in a bash script? Or is there a different, alternate mail command that will let me do so? (please include a description of syntax and how I'd package the above message text for the alternate method).
    Thanks in advance, all!

    Hi j.v.,
    The > after EOF is just a typo (or may be added by the Discussion ?) and you must delete it; other > are prompts from the interactive shell. Andy's post shows an interactive use of shell, not a shell script (note the shell prompt % in front of the commands). A typical use of here document may look like
    command <<ENDOFDATA
    ENDOFDATA
    There must be no spaces before and after ENDOFDATA. The word ENDOFDATA can be EOF or any other string which is guaranteed not to appear in the text (the .... in the example above).
    You can modify the From: header by using sendmail command (postfix has it as a compatibility interface):
    /usr/sbin/sendmail -t <<EndOfMessage
    Subject: test mail
    To: jv
    From: watchdog
    This is a test:
    ${VARIABLE[1]}
    ${VARIABLE[2]}
    This is the last line of the test message.
    EndOfMessage
    There must be a blank line between the headers and the mail body.
    I assume that you send these mails only to users on your local Mac. Please do not send mails to remote users by using the sendmail command unless you know what you are doing completely.
    PowerMac G4   Mac OS X (10.4.5)  

  • Bash script run via cron not executing MYSQL command

    I have a bash script which is run from a cron,
    It is executing as I have it write to a log file which it does correctly.
    I am wanting the bash script to restore a mysqldump file.
    When I run the bash script manually the dump file gets loaded fine. But when I run it through the cron the mysql command appears to be ignored.
    The mysqldump file is 54MB and I have checked to make sure that MYSQL is included in the global users path in /etc/profile
    Does anyone know why this maybe??
    Here is the bash file
    #!/bin/bash
    date >> /home/user/crons/crons.log
    echo "Started loadbackup" >> /home/user/crons/crons.log
    cd /home/user
    dbuser=root
    dbpass=password
    dbname=databasename
    filename=backup
    mysql -hlocalhost -u"$dbuser" -p"$dbpass" "$dbname" < " >> /home/user/crons/crons.log
    My crontab looks like
    02 17 * * * /home/user/crons/loadbackup.sh
    Many thanks
    Richard

    Hi Richard,
    Have you tried redirecting the script output in the cron to see if an error is being reported?
    I.e.
    02 17 * * * /home/user/crons/loadbackup.sh > /tmp/loadbackup.log 2>&1

  • [SOLVED] problem with spaces and ls command in bash script

    I am going mad with a bash script I am trying to finish. The ls command is driving me mad with spaces in path names. This is the portion of my script that is giving me trouble:
    HOMEDIR="/home/panos/Web Site"
    for file in $(find "$HOMEDIR" -type f)
    do
    if [ "$(dateDiff -d $(ls -lh "$file" | awk '{ print $6 }') "$(date +%F)")" -gt 30 ];
    then echo -e "File $file is $(dateDiff -d $(ls -lh "$file" | awk '{ print $6 }') "$(date +%F)") old\r" >> /home/panos/scripts/temp;
    fi
    done
    The dateDiff() function is defined earlier and the script works fine when I change the HOMEDIR variable to a path where there are no spaces in directory and file names. I have isolated the problem to the ls command, so a simpler code sample that also doesn't work correctly with path names with spaces is this:
    #!/bin/bash
    HOMEDIR="/home/panos/test dir"
    for file in $(find "$HOMEDIR" -type f)
    do
    ls -lh "$file"
    done
    TIA
    Last edited by panosk (2009-11-08 21:55:31)

    oops, brain fart. *flushes with embarrassment*
    -- Edit --
    BTW, for this kind of thing, I usually do something like:
    find "$HOMEDIR" -type f | while read file ; do something with "$file" ; done
    Or put those in an array:
    IFS=$'\n' ; files=($(find "$HOMEDIR" -type f)) ; unset IFS
    for file in "${files[@]}" ; do something with "$file" ; done
    The later method is useful when elements of "${files[@]}" will be used multiple times across the script.
    Last edited by lolilolicon (2009-11-09 08:13:07)

  • Set env using a script and run the command (dependency on the env)

    I need to set the env varaible by running a shell script with arguments as 'ksh setEnviron r6.1' and then run the command in the
    same process. the command has dependency on the previous script which sets the env variables.
    With Runtime.getRuntime().exec( cmd1); ,Runtime.getRuntime().exec( cmd2); I am not able to execute the Cmd2 as it is running in different process.
    How do solve this issue.
    Is there any other method to run the command to set env variables and run the second command.(dependent on the env) to get the output.
    Please help me out in this.

    ganesh_mak wrote:
    final String[] commands = {
                              ". setEnviron r6.1",
                                "/usr/add-on/test/Xbin/sql name from list where date.eq.05/22/08",
    Process penv = Runtime.getRuntime().exec("/bin/sh");
    BufferedReader br = new BufferedReader( new InputStreamReader( penv.getInputStream() ) );
    BufferedReader stdError = new BufferedReader(new InputStreamReader(penv.getErrorStream()));
    final OutputStream writer =  penv.getOutputStream();
    for (int i=0; i<commands.length;i++)
         writer.write(commands.getBytes("utf-8"));
         writer.write("\n".getBytes());
    String line;
    while((line = br.readLine())!=null){
    System.out.println(line);
    br.close();
    writer.close();
    I tried the above code but its not working...............
    please correct me.
    Do you think I used the '-i' argument just for fun? Did you do a 'man sh' and 'man bash' to see what the arguments do? If not then do it now.
    Do you think I used Theads to process stderr and stdout just for fun? I've shown you the basic approach. I have shown you how you need to create Threads to process stdout and stderr. If you have not understood and you have not studied http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html then do so now.
    Edited by: sabre150 on Jun 2, 2008 3:43 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Multiarchive RAR bash script (SOLVED)

    Dear Fellow Archies!
    I use the command
    rar a -w<working_folder> -m5 -v<max_volume_size> <archive_name> <target_file_or_folder>
    whenever I need to make a multiarchive rar file, because I have not yet found a GUI archive manager that does this.
    So, I've decided to write a simple bash script to make things easier.
    Here's the script:
    #!/bin/bash
    echo Please, enter the full path to the target file or folder [without the target itself]!
    read PATH
    echo Please, enter the target filename [with extension] or folder name!
    read TARGET
    echo Please, enter the desired archive name [without extension]!
    read DESTINATION
    echo Please, enter the desired volume size in KB!
    read SIZE
    rar a -w$PATH -m5 -v$SIZE $DESTINATION $TARGET
    Executing the last line of the code in terminal works without any hassle. When I run this entire script however, it doesn't.
    What needs to be changed for the script to work?
    RAR man page is HERE - CLICK, in case someone needs to take a look at something.
    Thank you and thank you,
    UFOKatarn
    Last edited by UFOKatarn (2012-05-03 07:38:28)

    Done! Working!
    Geniuz: Logout-login did it. How simple.
    Juster: I added "echo $PATH" to the script and ran it with "bash -x". And the output was the same as after the logout-login. Here it is, in case you are curious.
    /usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl:/opt/qt/bin
    Thank you all for your help guys :bow:.
    OFFTOPIC:
    All who intend to use Xfce launchers to run bash scripts: There are two options in the settings for each launcher: "Command" and "Working Directory". And when I had "Working Directory" filled with "/home/username/", the script didn't work. It worked perfectly after I blanked out the "Working Directory" option. Just so you know, in case someone doesn't .
    This has never happened to be before, but still, I guess it is better to do it with blank "Working Directory" and entering the entire path into the script in the "Command" field. It might be that Xfce launchers always stick to the "Working Directory", even though a script might tell them otherwise.
    Last edited by UFOKatarn (2012-05-03 07:38:05)

  • Sudo Command in Bash Script

    So I created a simple bash script to run on login.....
    one of the commands is the following:
    sudo "something something something"....
    One thing I haven't learned in my years of Unix is how do you get a bash script to run a sudo command without having to enter a password?  I know this is trival, but just a quick 'this is how you do it' would be cool.
    Thanks ahead of time on this really dumb question.

    There's a few ways to do this.  Here's two (pick the method you like):
    Method 1: Using "askpass".
    With this you always do sudo -A command.  The -A argument tells sudo to execute a command that echos the password to stdout.  That command is something you write.  For this explaination let's call the command pw and stick it /usr/local/bin.  So it's full pathname would be /usr/local/bin/pw.
    sudo -A can get the pathname to pw a number of ways.
    1. From the sudoers file.
    Use visudo to add the following line to the sudoers file:
    Defaults:ALL    askpass=/usr/local/bin/pw
    2. Using the SUDO_ASKPASS environment variable.
    export SUDO_ASKPASS=/usr/local/bin/pw
    This might work too (assuming SUDO_ASKPASS has been previously exported):
    SUDO_ASKPASS=/usr/local/bin/pw sudo -A command
    Method 2: Have sudo read the password from stdin
    echo -n password | sudo -S command
    The -S option tells sudo to read the password from stdin so echo pipes it in (without the ending newline).
    The only relatively secure scheme of these two methods is the askpass (-A) method.  At least with that method you have a chance of encrypting/hiding your password down in the command that echoes it to stdout.  The -S method would contain your password explicitly in a script somewhere unless you make other provisions to encrypt/hide it with that technique.

  • Problem running sudo command in script

    Hello,
    I try to run this script.
    #!/bin/bash
    sudo /bin/cat /dev/input/event1 >> /home/tom/.log/log.bin &
    The sudoers entry
    %users ALL= NOPASSWD: /bin/cat /dev/input/event1 >> /home/tom/.log/log.bin
    I get the following error!
    $ Passwort: sudo: pam_authenticate: Kommunikationsfehler
    Kommunikationsfehler = eng: communication error
    What's wrong with that?
    Thank you!
    clementis

    Sorry, for being not precise.
    I created the alias in .bashrc in my $home directory. In sudoers all users are allowed to key in this command without a passwort entry.
    I know how to autostart in xfce and so created an autostart entry but unfortunatly it doesn't work for my "special" command.
    What I did:
    1. I wrote a script (first post) and tried to autostart it in xfce. For that command I created an entry in sudoers in order to avoid enter root passwort. The script didn't start.
    Then...
    2. I created an autostart entry (deleted the first one - see point 1) and entered the whole command (cat .../event1 >> $home...) in the xfce autostart input window. The idea was to run the command directly and not through a script. But it didn't work.
    Therefore I tried to run alter the command to "bash cat .../event1 >> $home ...." Didn't work either.
    3. I also deleted the autostart entry no 2. and created the alias in .bashrc in my home directory. Now created a new autostart entry trying to start the alias. Didn't work.
    I also tried to set the Terminal option in the file $home/.config/autostart/log.desktop to "true".
    So it looked like this:
    [Desktop Entry]
    Encoding=UTF-8
    Version=0.9.4
    Type=Application
    Name=log
    Comment=event1
    Exec= sudo cat /dev/input/event1 >> /home/tom/.cblog/log.bin &
    StartupNotify=false
    Terminal=true
    Hidden=false
    The alias for example works well if I enter it in xterm.
    So, I don't know why it isn't working! :-(
    Thank you for any help
    Clementis

  • Unexpected token `(' in my bash script [Solved]

    I've been working on a bash script, and I'm trying to get it to move all directories that are not named certain names to another directory.
    EDIT: Fixed the thing papajoke pointed out
    #!/bin/bash
    mv ~/Downloads/!(folders|pics|docs|code|archives|vids|sounds)/ ~/Downloads/folders/
    The command from the script does what I want it to do when I run it from a terminal.
    It also works if I run the script as follows:
    source script.sh
    It doesn't work like this:
    bash script.sh
    I'm trying to get it to run when I login, and using the running the command with "source" in my MATE Startup Applications doesn't work.
    I'm new to bash scripting, any help would be much appreciated.  Thanks
    Last edited by physicsshark (2015-04-07 20:09:07)

    Trilby wrote:I've never seen that syntax
    You mean the pipes or the bang?
    $ touch a.gz b.gz c.txt
    $ ls !(*.gz)
    c.txt
    This works as an alias and from the comeliness commandline, but not in a script.
    $ ls -l ~/2
    total 16
    drwxr-xr-x 2 karol users 4096 Apr 7 03:13 a
    drwxr-xr-x 2 karol users 4096 Apr 7 03:07 b
    drwxr-xr-x 2 karol users 4096 Apr 7 03:07 c
    drwxr-xr-x 2 karol users 4096 Apr 7 03:13 d
    $ mv ~/2/!(a|b|c) ~/2/a
    $ ls -l ~/2
    total 12
    drwxr-xr-x 3 karol users 4096 Apr 7 03:14 a
    drwxr-xr-x 2 karol users 4096 Apr 7 03:07 b
    drwxr-xr-x 2 karol users 4096 Apr 7 03:07 c
    $ ls -l ~/2/a
    total 4
    drwxr-xr-x 2 karol users 4096 Apr 7 03:13 d
    Last edited by karol (2015-04-07 01:20:14)

Maybe you are looking for

  • Disable Bluetooth Option

    Our company deals with audio/video media provided by content providers and per MPAA guidelines we need our macs configured where no media content can be copied/transferred out of Macs via External Drives, Wireless, Bluetooth etc. I was able to config

  • Help~! - IOexception: Bigger type length than Maximum

    Hi all, I've been seeing errors below so often these days when I run my program. Anybody has any clue? "dberror= Error: java.sql.SQLException: Io exception: Bigger type length than Maximum dberror= Error: java.sql.SQLException: Bigger type length tha

  • CIM WIM/EIM sql templates for developing custom reports

    Hi there, We want to create custom reports from eGReport Database, where I can find the SQL queries are used in the reports are available from Report Console and then I'd be able to develop my custom reports? Thanks for your give a look into this.

  • Trying to install RAM, bottom panel is impossible to unscrew

    I just bought 8GB of RAM from Crucial for my 13" MacBook Pro. I am unable to unscrew the bottom panel to install the memory. So far I've destroyed 3 screwdrivers just trying to unscrew 1 screw. I've used Philips 00, as well as 0 for good measure - th

  • Image Persistence - Image Retention issues - iMac

    Hello everyone. When is Apple going to fix all the image retention issues, or as Apple would call it image persistence? I find it to be horrendous that Apple is calling this "normal". There is nothing normal about having an image ghosted or stuck on