Iwl3945 and dhcpcd workaround - bash script

I got tired of typing every command by hand all the time, so i made this simple bash script to do this for me...
edit the script with your preferences and settings and run it as root. The script sets a static ip, and all the shizzle thats needed to have a workaround for the dhcp not working
And im a newbie in bash programming, so please dont flame
anywho, please give med feedback if theres something i could do different and better
wlan script

Correct me if I'm wrong, but you could simply add the rmmod / modprobe stuff and all that in PRE_UP='' in any of your netcfg profiles and the just run netcfg <profile>.

Similar Messages

  • Bash script help?

    I really need to get a good book to read and learn some bash scripting so I can do this myself. but this is only the 3rd or 4th time i've come here asking
    I was hoping someone might be able to assist me again
    I'm trying to organize my movie folder again. I've let it go too long
    basically, i'm looking for a bash script to go through my folder of movies. each movie has it's own folder with an avi, jpg and nfo. I need the files in the folders to be the same name as the parent folder
    so lets say i have this
    movie title folder (2012)
    -movie_file_2012.avi
    -an_nfo_file.nfo
    -a_jpg.jpg
    I want to turn into this
    movie title folder (2012)
    -movie title folder (2012).avi
    -movie title folder (2012).nfo
    -movie title folder (2012).jpg
    anyone?

    ssl6 wrote:
    I really need to get a good book to read and learn some bash scripting so I can do this myself. but this is only the 3rd or 4th time i've come here asking
    I was hoping someone might be able to assist me again
    I'm trying to organize my movie folder again. I've let it go too long
    basically, i'm looking for a bash script to go through my folder of movies. each movie has it's own folder with an avi, jpg and nfo. I need the files in the folders to be the same name as the parent folder
    so lets say i have this
    movie title folder (2012)
    -movie_file_2012.avi
    -an_nfo_file.nfo
    -a_jpg.jpg
    I want to turn into this
    movie title folder (2012)
    -movie title folder (2012).avi
    -movie title folder (2012).nfo
    -movie title folder (2012).jpg
    anyone?
    I won't do the work for you, but if you're willing to look things up and try to write a working script that does what you've described--I'll be happy to help flush out problem areas.
    Okay, so what you want is to turn
    Movies/:
    A-Movie-I-love.avi
    A-Movie-I-love.nfo
    A-Movie-I-love.jpg
    A-Movie-about-Llamas.avi # :P
    A-Movie-about-Llamas.nfo
    A-Movie-about-Llamas.jpg
    into this:
    Movies/:
    A-Movie-I-love/:
    A-Movie-I-love.avi
    A-Movie-I-love.nfo
    A-Movie-I-love.jpg
    A-Movie-about-Llamas/:
    A-Movie-about-Llamas.avi
    A-Movie-about-Llamas.nfo
    A-Movie-about-Llamas.jpg
    right?
    Last edited by lspci (2013-04-23 20:40:30)

  • [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)

  • Can't get conky-cli and bash scripts to both display in dwm statusbar!

    I'm trying to configure my dwm status bar to display some simple information using conky-cli and bash scripts. At first I tried just letting conky run the bash scripts (for network and volume state), but this increased my cpu usage by about 5%, which is significant considering I normally have 1-3% usage when idle. Also, I wanted to keep conky because it makes the display of certain information easy, such as cpu & RAM usage.
    The problem is I'm having trouble getting both to display side by side. Here are the relevant parts of my .xinitrc:
    network(){
    iwconfig wlan0 2>&1 | grep -q no\ wireless\ extensions\. && {
    echo wired
    exit 0
    essid=`iwconfig wlan0 | awk -F '"' '/ESSID/ {print $2}'`
    stngth=`iwconfig wlan0 | awk -F '=' '/Quality/ {print $2}' | cut -d '/' -f 1`
    bars=`expr $stngth / 10`
    case $bars in
    0) bar='[-------]' ;;
    1) bar='[#------]' ;;
    2) bar='[##-----]' ;;
    3) bar='[###----]' ;;
    4) bar='[####---]' ;;
    5) bar='[#####--]' ;;
    6) bar='[######-]' ;;
    7) bar='[#######]' ;;
    *) bar='[--!!!--]' ;;
    esac
    echo $essid$bar
    exit 0
    volume(){
    vol=$(amixer get Master | awk -F'[]%[]' '/%/ {if ($7 == "off") { print "MM" } else { print $2 }}' | head -n 1)
    echo Vol: $vol%
    exit 0
    conky | while true; read line; do xsetroot -name "`$line` `volume` `network` `date '+%a %m-%d-%Y %I:%M%p'`"; done &
    exec dwm
    (let me know if it would help to post any other files)
    For some reason when I run this I only get the network/volume scripts and date running, updating every second (I think). The conky line just doesn't show up. I don't know what could be wrong, since I didn't see any error messages.
    An even better solution would be to just have shell scripts to display CPU and MEM usage. I have a dual-core cpu, cpu0 and cpu1. I'd like to see both percentages if possible, or at least a percentage that is an accurate average of the two or something. In conky-cli I have something that shows:
    cpu0/1: xx% xx%
    Also, seeing RAM usage would help a lot. In conky it shows:
    mem: xx% (xxxMB)
    These are the ways I would like to have bash scripts show them, if possible, but I have zero skill in bash programming. I made this an option in case it's easier/cleaner/less resource hungry than a conky solution. Personally, if they're about the same in these aspects, I would prefer something with conky and the shell scripts because conky is so extensible, yet it's only flaw is executing scripts with minimal resource usage.
    Help?

    Thanks. I was thinking of using load average to save a few characters, but I didn't quite understand the numbers. I'll try that once I get to my Linux box, but could you please explain or post a link to something that explains load average (what's low, high, normal, etc.)?
    EDIT: I found a website that explains loadavg. I now have my dwm status bar displaying it perfectly (yay!). Now I just need to add a few more things like battery status, etc. and I might be done. I'll probably post here if I have more questions, though.
    Thanks for your help!
    Last edited by Allamgir (2009-07-18 14:41:11)

  • Bash script read input and feh

    I was trying to make a quick script to organize some pictures using feh to display the picture in question and then using bash to read a character from the keyboard and move to a folder based on that letter. Problem is it opens every image in the folder at the start (which is overwhelming). I want to go image by image.
    heres the simplified script. There would be different if statements for each letter/dir pair
    #!/bin/bash
    ls | while read file1; do #while loop over all images in the dir
    feh $file1 &
    read ch1
    if [[ $ch1 == "e" ]]
    then
    mv $file1 /PATH/hawaii
    echo "moving to hawaii"
    pkill feh
    fi
    Problem seems to be that the script doesn't wait to receive the input $ch1 before moving on to the next iteration of the loop.  Except that when I do something simpler like the following it does seem to wait on the input
    while
       echo '1'
       read ch1
       echo '2'
       echo '3'

    for f in *; do $(feh $f)& read g; if [[ "$g" == "e" ]]; then mv -v $f ../tested; fi;pkill feh; done;
    waits for me to enter something before checking whether to move the image and closing the image and moving to the next.

  • Bash script workaround for intel backlight problems

    Hi all,
    I have LXDE with kernel 2.6.30, xf86-video-intel-newest (2.8 rc) on my Samsung NC10, and like many people I have been unable to change the backlight settings in X with kms turned on.
    I have tried the various solutions on the forum and none of them work for me, so here are two little bash scripts that use the setpci command to change the backlight.
    Note 1: I have a little file .backlight in my home dir that I store the backlight setting because I don't know how to read the value back from the pci address. So if you use this script you need to do this first:
    echo FF > ~/.backlight
    Note 2: These scripts also requre bc from extra to do the hex conversion & maths.
    sudo pacman -Sy bc
    It's only 240 K in size, but if you are trying to keep the number of installed packages low, then you won't like this
    Here is the package details from pacman:
    Name : bc
    Version : 1.06-5
    URL : None
    Licenses : GPL
    Groups : None
    Provides : None
    Depends On : readline
    Optional Deps : None
    Required By : None
    Conflicts With : bc-readline
    Replaces : bc-readline
    Installed Size : 240.00 K
    Packager : Allan McRae <[email protected]>
    Architecture : i686
    Build Date : Sat 02 Aug 2008 14:18:04 IST
    Install Date : Thu 25 Jun 2009 16:06:53 IST
    Install Reason : Explicitly installed
    Install Script : No
    Description : An arbitrary precision calculator language
    bc /usr/
    bc /usr/bin/
    bc /usr/bin/bc
    bc /usr/bin/dc
    bc /usr/share/
    bc /usr/share/info/
    bc /usr/share/info/bc.info
    bc /usr/share/info/dc.info
    bc /usr/share/man/
    bc /usr/share/man/man1/
    bc /usr/share/man/man1/bc.1.gz
    bc /usr/share/man/man1/dc.1.gz
    You also need to know the address of you graphics card:
    lspci | grep Display
    For me this returns:
    00:02.1 Display controller: Intel Corporation Mobile 945GM/GMS/GME, 943/940GML Express Integrated Graphics Controller (rev 03)
    This is needed for this command in the scripts:
    sudo setpci -s 00:02.1 F4.B=$var3
    Note the 00:02.1 is the address for my laptop screen, 00:02.0 is the address for the vga out controller for me.
    Increase backlight:
    #!/bin/bash
    var1=`cat ~/.backlight`
    var2=`echo "16 i $var1 F + p"|dc`
    if (( ( "$var2" \> "-1") && ( "$var2" \< "256" ) ));
    then
    var3=`echo "10 i 16 o $var2 p"|dc`
    echo $var3 > ~/.backlight
    sudo setpci -s 00:02.1 F4.B=$var3
    fi
    Decrease backlight:
    #!/bin/bash
    var1=`cat ~/.backlight`
    var2=`echo "16 i $var1 F - p"|dc`
    if (( ( "$var2" \> "-1") && ( "$var2" \< "256" ) ));
    then
    var3=`echo "10 i 16 o $var2 p"|dc`
    echo $var3 > ~/.backlight
    sudo setpci -s 00:02.1 F4.B=$var3
    fi
    Obviously someone else can write a much smarter/better set of scripts than me, but I hope is can be of use for someone!
    Edit:Here are my openbox bindings for the scripts:
    <keybind key="XF86MonBrightnessUp">
    <action name="Execute">
    <command>~/bin/blightu.sh</command>
    </action>
    </keybind>
    <keybind key="XF86MonBrightnessDown">
    <action name="Execute">
    <command>~/bin/blightd.sh</command>
    </action>
    </keybind>
    Last edited by makimaki (2009-07-11 14:26:08)

    FYI: The new xf86-video-intel (2.9) has just been released:
    http://article.gmane.org/gmane.comp.fre … xorg/40733
    According to the release announcement, the new driver fixes the backlight issue with KMS:
    * Add support for BACKLIGHT property when using kernel modesetting
      (KMS). This allows backlight adjustment with programs such as
      "xbacklight -set <percentage>" or "xrandr --set BACKLIGHT <value>".

  • My first bash script - update mirrors and then update your system.

    Like the title says, this is my first attempt at a bash script.
    I wrote it to make it a tiny bit easier for my wife to keep her system up to date without needing to remember the terminal commands.  She runs it via an entry in her openbox menu.
    It calls on reflector to check all available mirrors for the most up to date and then use rankmirrors to find the fastest 5 and write them to /etc/pacmand.d/mirrorlist
    Finally, it syncs and upgrades via the command pacman -Syyu
    #!/bin/bash
    # runs reflector to optimize mirrors
    echo "I'm afraid I can't do that Dave"
    sudo reflector -l 5 -r -o /etc/pacman.d/mirrorlist
    echo " I hope you trust me..."
    echo " "
    sleep 2s
    # updates system
    sudo pacman -Syyu

    I've scavenged some code to take care of the root thing, but why rebase vs pacman?  After reading up on rebase a bit, I'm not quite sure how to use it to complete the upgrade once it's updated everything.

  • Differences in writting bash-script in Solaris and in RHEL?

    I wrote a script 'checkinstall' as follow and it works fine by RHEL:
    [code]
    #!/bin/sh
    HOSTNAME=hostname
    echo $HOSTNAME
    if [ $HOSTNAME == "S001AP99-TEST" ]; then
        echo This is the wrong machine.\
        echo "\nAbouting installation.\n\n"
        exit 1
    fi
    exit 0
    [/code]
    But when I run this by Solaris I got:
    # ./checkinstall
    hostname
    ./checkinstall: test: unknown operator ==
    I changed the line HOSTNAME=hostname to HOSTNAME=`hostname` and it outputs the correct hostname.
    But I still get error:
    # ./checkinstall
    S001AP99-TEST
    ./checkinstall: test: unknown operator ==

    If you want to create bash scripts, then the first step is to set the right shell in the first line => #!/bin/bash
    Then, after this important step, you can try if this works. Oh surprise, it's working.

  • Double-clicking a Bash script and having it execute in it's directory

    Hi. I'm having some trouble with a Bash script I've been working on.
    The first command in the script is to copy all of the contents of the directory it's located in (including itself) to another folder.
    The Bash command I'm using is:
    cp -R . "/Some/Other/Folder/"
    This works fine when I run the program from the Terminal. E.g.: ./testscript
    But, I need this script to be double clickable in the Finder. I've associated it with Terminal, but when I double-click on it, instead of copying the files from the script's local folder, it starts recursively copying files from the home folder!
    I think this is because when I double-click on the script, it starts a new Terminal window at the home folder, and the dot portion of "cp ." now refers to the home folder, instead of the directory containing the script.
    Can anyone help me figure out how to be able to double click on the script to run it, yet have the script start in it's original folder?
    Thanks for any help.
    -Bassam
    Macbook Pro   Mac OS X (10.4.6)   Recently switched from Windows XP

    Thanks Steve, that worked perfectly.
    I did have to add a / to "$myFolder/" in the second line, so that the contents of the folder was copied, not the folder itself.
    Thanks!

  • Bash script user input and revision technique requested

    In a bash script, I have a need to present the contents of a variable to the user, so that he can "revise" the value if needed, or just hit enter if no revision is required. The objective is to reduce keyboard effort to just revising a presented value.
    The "hit enter to continue" part is easy.
    The "revise" part is the problem for me.
    To illustrate using an example:
    #! /bin/bash
    position_var=30.39
    echo -n "Revise Position if required:${position_var}"
    #then some kind of read position_var ??
    How can I make the position_var available to the user to edit and resubmit?
    Thanks
    steve.
    Last edited by stevepa (2012-02-28 17:31:56)

    The above solution is good okay for a general shell script, bash has a feature for what you want though. (see below)
    If however the content of the variable is bigger (multiple lines, or a really LONG line you don't want to have to retype), you have 2 options:
    Write it to a temp file and fire up $EDITOR (if that's not set, you can default to nano or vi, whichever you can find with $(which ...)).
    The other idea that comes to mind is using 'expect' to present a prefilled prompt the user can edit... I'll have to test this...
    EDIT: Can't think of an easy way to do that with expect... mhh...
    EDIT2: Specifically for bash:
    read -p "Revise Position if required: " -i "$current" -e new
    with the -e flag, $current will be what the line is prefilled with, and $new will contain the result.
    Last edited by Blµb (2012-02-28 18:14:55)

  • Small bash script as userspace daemon?

    Hi!
    I have a small bash script that I want to execute every 5 minutes. It's not vital, I'll notice if it stops working soon enough, so I'd like to get it out of my sight (both how it's started and when it's running - especially I don't want cron spamming the journal all the time. If it's convenient, I might try to pipe some assorted output to logger somehow, but that's not important). Now I'm trying to figure out how something like that is supposed to be done...:
    I have questions like...:
    - Should I modify the script so it has an infinite wait-5minutes-loop itself? And how do I make it break out of the loop if the service-handle-thingy tells it to / does it have to react to environment variables from something?
    - Should I create a service file for systemd or what is supposed to handle such "pseudo userspace daemons"? While I found information on how to create the service files, I couldn't really figure out how the script behind it should look...
    - Also I'm not sure if "daemons" should be executed as root and use sudo or something to do userspace stuff... or if the whole thing should be started as user.
    I found only obsolete looking information on all of those things and examples that are specific to other distributions (saw lot of "start-stop-daemon" - I guess that's debian or something, not archlinux...?). So: Could someone please bump me into the general direction of the stuff I need to use / read?
    Thanks!

    whoops wrote:
    Thanks!
    Phew, that was a lot of stuff... browsed many examples too... and in the end it looks like the crontab was the "right" place to put that thing after all, everything else just seems like a "dirty" or overkill solution in comparison...
    The only thing that still irritates me is cron insisting to write every single freaking *success* into the logs (/journal) instead of just warnings / errors. I really don't need that thing telling me: "Hi, I'm still OK! " every other minute -.- but there does not seem to be an option (other than installing a syslog-daemon capable of "blacklisting" the entries as a workaround) to shut it up... which was the reason why I first thought that scripts which are to be executes so often don't belong into the crontab.
    Hmm... not sure what to do yet. Is there anything else I should know / read before I make up my mind and stop looking for a better solution to this?
    Which cron do you use? I have dcron installed and it has a log level setting - see man crond

  • Bash script to connect to strongest unencrypted wifi AP

    Here's a little bash script that looks at the available wifi APs that your card can see, and automatically connects you to the AP with the highest quality and that is also unencrypted. I'm just posting it in case anyone wants to improve upon it or use it. And yes, my bash knowledge kinda sucks.
    Just call it like "wifi.sh wlan0" as root.
    #!/bin/bash
    # Finds the strongest unencrypted AP and tries to connect to it via dhcp
    # Call this script like "wifi.sh wlan0"
    interface=$1
    iwlist $interface scan > blah
    NumAPs=`cat blah | grep ESSID | wc -l`
    BestAP=0
    BestQuality=-1
    for i in `seq 1 $NumAPs`;
    do
    # Check if AP is encrypted
    Encryption=`cat blah | grep Encryption | head -n$i | tail -n1 | cut -d":" -f2`
    if [ $Encryption = "off" ]; then
    # Find AP with the highest quality
    QUALITY=`cat blah | grep Quality | head -n$i | tail -n1 | cut -d":" -f2 | cut -d"/" -f1 | sed 's/ //g'`
    if [ $QUALITY -gt $BestQuality ]; then
    BestQuality=$QUALITY
    BestAP=$i
    fi
    fi
    done
    if [ $BestAP -gt 0 ]; then
    # Yay, we found an unencrypted AP:
    echo Connecting to...
    ESSID=`cat blah | grep ESSID | head -n$BestAP | tail -n1 | cut -d""" -f2`
    echo ESSID=$ESSID
    MODE=`cat blah | grep Mode | head -n$BestAP | tail -n1 | cut -d":" -f2`
    echo Mode=$MODE
    CHANNEL=`cat blah | grep Channel | head -n$BestAP | tail -n1 | cut -d"(" -f2 | sed 's/Channel //g' | sed 's/)//g'`
    echo Channel=$CHANNEL
    # Connect
    iwconfig $interface essid $ESSID mode $MODE channel $CHANNEL
    if [ -e /etc/dhcpc/dhcpcd-${interface}.pid ]; then
    rm /etc/dhcpc/dhcpcd-${interface}.pid
    fi
    dhcpcd $interface
    # Cleanup
    rm blah
    fi

    For whatever reason, your quality line uses an equal sign whereas every other line of your scan has a colon (and most people have a colon for every line). Too weird..
    Anyway, give this a shot:
    #!/bin/bash
    # Finds the strongest unencrypted AP and tries to connect to it via dhcp
    # Call this script like "wifi.sh wlan0"
    TEMP=/tmp/bestap.tmp
    LOCK=/var/lock/bestap.lock
    if [ `whoami` != "root" ];then
    echo "Sorry, you need to be root to run this program"
    exit 1
    fi
    if [[ -z $1 ]];then
    echo "USAGE: $0 device"
    exit 1
    else
    interface=$1
    fi
    # Checking for lock
    if [[ -e $LOCK ]];then
    exit 1; # Too simply nothing to do here :)
    else
    touch $TEMP $LOCK
    fi
    isNotInteger()
    x=$1
    case $x in
    *[!0-9])
    return 0 ;;
    return 1 ;;
    esac
    # Proggy
    iwlist $interface scan > $TEMP
    NumAPs=`cat $TEMP | grep ESSID | wc -l`
    BestAP=0
    BestQuality=-1
    for i in `seq 1 $NumAPs`;
    do
    # Check if AP is encrypted
    Encryption=`cat $TEMP | grep Encryption | head -n$i | tail -n1 | cut -d":" -f2`
    if [ $Encryption = "off" ]; then
    # Find AP with the highest quality
    QUALITY=`cat $TEMP | grep Quality | head -n$i | tail -n1 | cut -d":" -f2 | cut -d"/" -f1 | sed 's/ //g'`
    if isNotInteger "$QUALITY"; then
    # If we didn't find an integer, try this instead:
    QUALITY=`cat $TEMP | grep Quality | head -n$i | tail -n1 | cut -d"=" -f2 | cut -d"/" -f1 | sed 's/ //g'`
    fi
    if [ "$QUALITY" -gt "$BestQuality" ]; then
    BestQuality=$QUALITY
    BestAP=$i
    fi
    fi
    done
    if [ $BestAP -gt 0 ]; then
    # Yay, we found an unencrypted AP:
    echo Connecting to...
    ESSID=`cat $TEMP | grep ESSID | head -n$BestAP | tail -n1 | cut -d""" -f2`
    echo ESSID=$ESSID
    MODE=`cat $TEMP | grep Mode | head -n$BestAP | tail -n1 | cut -d":" -f2`
    echo Mode=$MODE
    CHANNEL=`cat $TEMP | grep Channel | head -n$BestAP | tail -n1 | cut -d"(" -f2 | sed 's/Channel //g' | sed 's/)//g'`
    echo Channel=$CHANNEL
    # Connect
    iwconfig $interface essid $ESSID mode $MODE channel $CHANNEL
    if [ -e /etc/dhcpc/dhcpcd-${interface}.pid ]; then
    rm /etc/dhcpc/dhcpcd-${interface}.pid
    fi
    dhcpcd $interface
    # Cleanup
    fi
    rm -f $TEMP $LOCK

  • 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)  

  • What do you think of my Bash Script? What about the error checking?

    Well what do you think of this Bash script
    It works
    I gave it some problems (i.e. unpluged the ethernet, messed up the URL's, uninstaled some programs...) to see if would report errors and stop or just keep going... But it did
    I just kind of thought up a way to do some error checking with the commands that I know.....
    What is a better way to do error checking?
    What do you think I should add/Do to this script?
    #!/bin/bash
    # Shell script to make a USB Tumb Drive for Flashing BIOS on a Lenovo Ideapad Y510.
    # This script needs to be owned and run as ROOT with the "sudo command"
    # i.e. sudo usbbiosflasher
    # If you have anyideas send me a PM on ubuntufourms.org my user name is HunterThomson
    # Name/Rename this script usbbiosflasher and save it to the ~/home directory.
    # Then run the command- chown root:root usbbiosflasher
    # Then run the command- chmod 755 usbbiosflasher
    # Then copy the script to the directory /usr/bin.
    # Run this comand to do that- sudo cp ~/usbbiosflasher /usr/bin
    # You also must have the program "mbr" installed
    # You can install the mbr program by running this comand in the shell on Ubuntu
    # sudo apt-get install mbr
    # In Arch Linux you have to get it from Aur
    # First you will need to know a few things...
    # You will also need to know the Mount Point i.e. /media/disk and the /dev path i.e. /dev/sdb1.
    # You can find these by using the df -T comand.
    # Run df -T in the shell. Then plug in the USB Thumb Drive and run the df -T comand agin.
    # The new listing is the USB Thumb Dirve.
    # Also check to make sure the File System tipe is vFAT or FAT16 or FAT32.
    # If it is not use gparted to format it to FAT32.
    # I am farly certen that all USB Thumb drives come formated with FAT file system out of the BOX.
    # You may want to fromat it anyway just to make sure.
    echo "Interactive Shell Script to Make a USB Thumb Drive \for Flashing BIOS On a Lenovo Ideapad Y510"
    echo ""
    echo "You will need to have the program mbr installed"
    echo "If you are on Ubuntu Linux you can retreve it form the repositories"
    echo "If you are on Arch Linux you will need to get it from the Aur repository"
    echo "Open anuther shell and \do that now..."
    echo ""
    verify="n"
    while [ "$verify" != y ]
    do
    printf "Do you have mbr installed... yes or no?"
    read AN1
    echo ""
    printf "You answered... $AN1 I have installed mbr. Is this correct... y or n?"
    read verify
    done
    echo ""
    if [ "$AN1" == "no" ]
    then
    echo "Install mbr now. Then run this script agin"
    exit
    else
    echo "contunuing script"
    fi
    echo ""
    # The next comand will make a directory to put needed files into. Note this file and everything init will be owned by root.
    mkdir ~/usbbiosfiles && check1="yes"
    if [ "$check1" = "yes" ]
    then
    echo "Made directory usbbiosfiles... OK"
    else
    echo "Could not \make directory usbbiosfiles"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    exit
    fi
    # The next two comands will get the FreeDOS file and the .ROM file.
    cd ~/usbbiosfiles && checka="yes"
    if [ "$checka" = "yes" ]
    then
    echo "Changing to the usbbiosfiles directory... OK"
    else
    echo "Could not Change to the usbbiosfiles directory"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    wget "http://www.fdos.org/bootdisks/autogen/FDOEM.144.gz" && check2="yes"
    if [ "$check2" = "yes" ]
    then
    echo "Download of FreeDOS... OK"
    else
    echo "Could not Download FreeDOS"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    wget "http://ubuntuforums.org/attachment.php?attachmentid=78460&d=1216648756" && check3="yes"
    if [ "$check3" = "yes" ]
    then
    echo "Download of the BIOS.ROM \file... OK"
    else
    echo "Could not Downlad the BIOS.ROM \file"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    # The next comand will name the .ROM file to the right name.
    mv ~/usbbiosfiles/attachment.php?attachmentid=78460\&d=1216648756 ~/usbbiosfiles/06CN29WW.bios.update.tar.bz2 && check4="yes"
    if [ "$check4" = "yes" ]
    then
    echo "Renameing of the BIOS.ROM \file... OK"
    else
    echo "Could not rename the BIOS.ROM \file"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    echo ""
    # The next two comands set the variables. DEVX for the path i.e. /dev/xxx and MOUNTX for the mount point i.e. /media/xxx
    verify="n"
    while [ "$verify" != y ]
    do
    echo "You will need to know the Mount Point and the dev Path. You will also need to \make sure the File System \type is vFAT, FAT16 or FAT32."
    echo ""
    echo "With the USB Thumb Drive unpluged, Open another shell and run the comand df -T Then plug \in the USB Thumb Drive and run the comand df -T one \more time. The new device listed is the USB Thumb Drive. Note the Mount Point and The dev Path and the File system Type i.e. vFAT... If the File System \type is not vFAT, FAT16 or FAT32 you will need to fromat it with gparted. You may want to format the USB Thumb Drive anyway just to \make sure. In any \case delete all files and directorys on the USB drive before you go any ferther with this program."
    echo ""
    printf "Enter the dev path the USB Thumb Drive is at?"
    read DEVX
    echo ""
    echo "Are you sure $DEVX is the dev path of the USB Thumb Drive... y or n?"
    read verify
    done
    echo ""
    verify="n"
    while [ "$verify" != y ]
    do
    printf "What is the Mount Point of the USB Thumb Drive?"
    read MOUNTX
    echo ""
    echo "Are you sure $MOUNTX is the Mount Point of the USB Drive... y or n?"
    read verify
    done
    echo ""
    install-mbr --enable A1 --partition 1 --force --timeout 0 $DEVX && check5="yes"
    if [ "$check5" = "yes" ]
    then
    echo "Installing MBR on USB Thumb Dirve... OK"
    else
    echo "Could not install MBR on USB Thumb Drive"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    tar xjf ~/usbbiosfiles/*.tar.bz2 && check7="yes"
    if [ "$check7" = "yes" ]
    then
    echo "Unpacking BIOS.ROM file... OK"
    else
    echo "Could not unpack BIOS.ROM file"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    gunzip ~/usbbiosfiles/FDOEM.144.gz && check8="yes"
    if [ "$check8" = "yes" ]
    then
    echo "Unpacking FreeDOS files... OK"
    else
    echo "Could not unpack FreeDOS files"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    mkdir ~/usbbiosfiles/fdoem144 && check9="yes"
    if [ "$check9" = "yes" ]
    then
    echo "Made directory fdoem144 in direcoty usbbiosfiles... OK"
    echo ""
    echo "Going to \sleep \for 5secs"
    else
    echo "Could not make directory fdoem144 in usbbiosfiles directory"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    modprobe loop && sleep 5 && check0="yes"
    if [ "$check0" = "yes" ]
    then
    echo "Modprobeing loop... OK"
    else
    echo "Could not \modprobe loop"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    mount -o loop ~/usbbiosfiles/FDOEM.144 ~/usbbiosfiles/fdoem144 && check10="yes"
    if [ "$check10" = "yes" ]
    then
    echo "Mounting FreeDOS on the fdoem144 directory... OK"
    else
    echo "Could not \mount FreeDOS on the fdoem144 directory"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    cp ~/usbbiosfiles/fdoem144/* $MOUNTX && check11="yes"
    if [ "$check11" = "yes" ]
    then
    echo "Copying FreeDOS files to $MOUNTX... OK"
    else
    echo "Could not copy FreeDOS files to $MOUNTX"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    cp ~/usbbiosfiles/*.ROM $MOUNTX && check12="yes"
    if [ "$check12" = "yes" ]
    then
    echo "Copying BIOS.ROM files to $MOUNTX... OK"
    else
    echo "Could not copy BIOS.ROM files to $MOUNTX"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    sync && check13="yes"
    if [ "$check13" = "yes" ]
    then
    echo "Runing the syncing command... OK"
    else
    echo "Could not run the syncing command"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    umount ~/usbbiosfiles/fdoem144 && check14="yes"
    if [ "$check14" = "yes" ]
    then
    echo "Unmounting of FreeDOS... OK"
    else
    echo "Could not unmount FreeDOS"
    echo "Look above for errors or problems reported and fix the problem"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this script agin"
    rm -r ~/usbbiosfiles
    exit
    fi
    verify="n"
    while [ "$verify" != y ]
    do
    printf "Do you see any errors... yes or no?"
    read AN2
    echo ""
    printf "You answered... $AN2 to errors. Is this correct... y or n?"
    read verify
    done
    echo ""
    if [ "$AN2" == "yes" ]
    then
    echo "User Repoted... Error"
    echo "Look above for errors or problems reported and fix the problem"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this script agin"
    rm -r ~/usbbiosfiles
    exit
    else
    echo "Success"
    echo "I did a lot of error checking too and didnt find anything"
    echo ""
    echo "Go get a pen and paper to write down these instructions"
    printf "Then hit the Enter to continue"
    read WAIT
    echo ""
    echo "Now leave the USB Thumb Drive pluged into your computer and Reboot. When the Lenovo Logo POST screen appears hit F2 to enter the CMOS setup utility. Go over to BOOT tab and go down to HardDrive \(Not Boot Order) \then \select the USB Thumb Drive as the 1st hard drve. Then F10 and yes to save changes. Your compter will reboot agin. Then when the Lenovo Logo POST Screen appers on reboot hit F4 to enter the BIOS FLASHING program. The USB Thumb Drive will be seen as the C drive \in the list on the Left, Select it. Then \select the .ROM \file \in the list on the Right and start the BIOS FLASH. \(NOTE Your hart may stop beating... This is normal) Pray to any God you know of and your computer should restart just like normal. Hit F2 and the BIOS will now stay it is 06CN29WW. You will need to \set the boot order to the way you like it and other things \if you need to because they have been changed to the default."
    fi
    echo ""
    echo "End of script"
    Last edited by hunterthomson (2008-08-10 11:17:47)

    Personally.....  (this is just how I would have written it - if it works, then it's good enough for me though )
    I would change this whole block:
    verify="n"
    while [ "$verify" != y ]
    do
    printf "Do you have mbr installed... yes or no?"
    read AN1
    echo ""
    printf "You answered... $AN1 I have installed mbr. Is this correct... y or n?"
    read verify
    done
    echo ""
    if [ "$AN1" == "no" ]
    then
    echo "Install mbr now. Then run this script agin"
    exit
    else
    echo "contunuing script"
    fi
    To this much shorter code:
    MBR='/usr/bin/install-mbr' # Or where ever you expect it to be
    if [ ! -x $MBR ] ; then
    echo "mbr doesn't appear to be installed."
    echo "If it is installed, check it's location, make sure it's executable and then make sure the MBR variable in this script is correct"
    exit 1
    fi
    I wouldn't have used the checkXX variables for each stage:
    mkdir ~/usbbiosfiles
    if [ $? != 0 ] ; then
    #failed
    echo "Could not \make directory usbbiosfiles"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    exit 1
    else
    echo "Made directory usbbiosfiles... OK"
    fi
    There is an issue with the way you do your verifications - the user can never get out unless they answer 'y' or hit CTRL+C. Something like this gives them options:
    verify="n"
    while [ "$verify" != "y" && "$verify" != "n" ]; do
    echo "You need to answer 'y'es or 'n'o"
    read verify
    echo $verify | tr "[:upper:]" "[:lower:]" # This converts the answer to lowercase so replies entered in upper case will still work
    done
    if [ $verify != 'y' ] ; then
    exit 1
    fi
    One last thing I try to do in scripts... Declare all your binaries as variables at the start of the program, then execute the binary program by using the variable. For example:
    # Binaries
    TAR='/bin/tar'
    CP='/bin/cp'
    CHMOD='/bin/chmod'
    # Execute tar and chmod the created file
    $TAR cvzf /tmp/tarfile.tar.gz /etc/*.conf
    $CHMOD 400 /etc/*.conf
    This way, it's easy to change the path in future without having to hunt through the script if the paths change, and it also ensures you're calling the programs using the full paths to make sure you're not executing some strange variant or alias that someone has setup. If I use `chmod` 30 times in a script, and the path changes in the future or on a different system (`chmod` is a bad example cause it's highly unlikely to change, but you know what I mean), then all you need to do is update the variable at the start of the script, and it all works again without having to script-hunt and change it 30 times.

  • /etc/rc.d/network: bash script: how to find out, if there was an error

    hello!
    i want to write a bash script for my wireless lan. for this i need the information, if the network daemon has connected successfully or failed.
    but there is a big problem: starting network success' every time, whether there was an error or not:
    $ /etc/rc.d/network start
    :: Starting network profile: 00wlan_home [BUSY]
    Error for wireless request "Set Mode" (8B06) :
    SET failed on device wlan0 ; No such device.
    [FAIL]
    :: Starting Network [DONE]
    $ ls /var/run/daemons/
    ... network ...
    can someone help me please? how can i realize  that "::Starting Network ..." also fails and the script returns an exit status 1?
    thanks for your help, maybe we can improve the script. but i'm not a geek in bash!
    mfg iggy

    iggy wrote:
    hello!
    i want to write a bash script for my wireless lan. for this i need the information, if the network daemon has connected successfully or failed.
    but there is a big problem: starting network success' every time, whether there was an error or not:
    $ /etc/rc.d/network start
    :: Starting network profile: 00wlan_home [BUSY]
    Error for wireless request "Set Mode" (8B06) :
    SET failed on device wlan0 ; No such device.
    [FAIL]
    :: Starting Network [DONE]
    $ ls /var/run/daemons/
    ... network ...
    can someone help me please? how can i realize  that "::Starting Network ..." also fails and the script returns an exit status 1?
    thanks for your help, maybe we can improve the script. but i'm not a geek in bash!
    mfg iggy
    try using netcfg to start the wireless profile, that should keep you happy until the new network scripts are unleashed... which won't have this problem.
    James

Maybe you are looking for

  • Export all tracks as audio files in LPX has suddenly ceased to function correctly

    I have been working on a project for the past three months, which requires me to work from home ,then export all my tracks as audio files and take them into another studio. This is because my collaborator's DAW of choice is now Nuendo. So far, this h

  • K9VGM-V vs skype video calling

    When I launched viceo calling in skype http://kepfeltoltes.hu/061018/k9vgmvsypevideo_www.kepfeltoltes.hu_.jpg bsod in matrix style 

  • Look for USER EXIT/Program similar with BADI:  BADI_SCD_ACCTG for SAP 4.5B

    Hello SAP Guru,           We are having the challenging in performing posting to multiple G/L accounts per shipment. This is required, for example, if customer, interplant, and/or inbound orders are combined onto one shipment.          We found this

  • Can load Snow Leopard on newest MBP?

    If I buy the current model 17" MacBookPro (called early 2011), can I do a clean install of Snow Leopard instead of using Lion? I have a Family Pack of Leopard, and the upgrade disks to Snow Leopard; would that work? When this model came out earlier t

  • Calculation Script on page 2 with data from page 1?

    I am missing something simple here.. I am wanting to write a calculation script using the sum of two numeric fields on page one divided by the sum of two numeric fields on page two. The only thing I can get to work is if I do a numeric field on page