Bash script to mount/umount usb ?

this thread https://bbs.archlinux.org/viewtopic.php?id=185712 gave me an idea and teach me.
I created a script to mount/umount usb. Save it in user's home dir, do
chmod
and click on it as a toggle button to mount/umount usb.
It only work for one usb plugged in. Please suggest me to get it work for two or more.
#! /bin/bash
# mr = mounted result
# ur = umounted result
# er = empty result
# cm = check mountpoint
# cup = check usb is plugged in
# usb = usb device (Example... /dev/sdb1)
cm=$(mountpoint /home/username/tmp)
cup=$(lsblk | grep "sd[b-z]1")
usb=$(ls /dev/sd[b-z]1)
er=""
ur="/home/username/tmp is not a mountpoint"
mr="/home/username/tmp is a mountpoint"
if [ "$cm" == "$ur" ] && [ "$cup" != "$er" ]; then
echo "password" | sudo -S mount -o uid=username,gid=users $usb /home/username/tmp
elif [ "$cm" == "$mr" ] && [ "$cup" != "$er" ]; then
echo "password" | sudo -S umount /home/username/tmp
else
exit
fi

There are a number of issues with your script; the reason you can't mount more than one device is that if "${usb[@]}" is populated by more than one drive, you need to iterate over the array to mount them.
Other issues that you should consider are:
your variable names are brief to the point of unintelligble: it is very hard to follow what is going on with "$mr", "$ur", "$cr" etc
don't parse the output of `ls`
don't put messages in variables; `printf` them
relatedly; check exit status, not strings: `$?`
if you are using bash; see What is the difference between [ and [[?
rather than `echo`ing your password (see 3), add the script to `sudoers`
Hope (some of) that helps.

Similar Messages

  • [SOLVED] Bash scripts to mount & unmount optical drive in Worker?

    I'm running XFCE on Arch with the HAL daemon being called in /etc/rc.conf.
    I can access media on my optical drive (DVD's or CD's) through the desktop icon that appears after HAL has recognised the drive, VLC automatically does its thing as does NeroLinux.
    The reason I'm posting is that I found a great DOpus clone yesterday called Worker - http://www.boomerangsworld.de/cms/worker/index?lang=en, which I am in the process of configuring.
    A problem I have is being able to access the optical drive via Worker.
    The way it is on my system, with HAL handling it, the first line (see below) appears after HAL mounts the media, which basically makes the two lines below it useless:
    /media/<title of disk>
    /media/cd
    /media/dvd
    I have tried configuring Worker to use /media/dvd (or cd), to access the optical media, these don't work for the reason stated above, & /dev/sd0 doesn't work either.
    So, do I have to turn off HAL, uncomment the lines in fstab & use mount?
    A little bash script, that would do the job for me would be great, as Worker will accept a script or a command string.
    I am a bash baby, so if someone can see a solution please post it?
    All input welcome.
    Thanks.
    Last edited by handy (2008-11-19 04:11:02)

    Zariel wrote:
    i guess something like this?
    %optical ALL=(ALL) NOPASSWD: ALL
    I found the clues for this in the sudoers manual:
    handy   ALL = NOPASSWD: /sbin/umount /CDROM,\
                    /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM
    Which works in so far as now mounting no longer needs the password.
    Which leaves me with the problem of trying to understand how to get Worker to mount the optical drive on command.
    If I enter the bash command in the Terminal as follows:
    mount /mnt/dvd
    the media is mounted, after which I can push the button in Worker, which I have configured with:
    /mnt/dvd
    & the root list of the optical media is displayed in the active panel of Worker.
    I just haven't been able to get Worker to use "mount /mnt/dvd" yet, there will be a way, I wonder how long it will take me to find it? lol
    Last edited by handy (2008-11-19 06:48:09)

  • Udev bash script for autodialing usb huawei modem

    Hey
    I've got an interesting one here.
    I have scripted up a bash script to be triggered by a udev add event for my usb modem. As far as I can tell the udev event is firing correctly according to udevadm.
    ACTION=="add", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1003", RUN+="/bin/sh /usr/local/bin/huawei_key.sh add"
    ACTION=="remove", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1003", RUN+="/bin/sh /usr/local/bin/huawei_key.sh remove"
    And heres the code from the script
    #!/bin/bash
    #returns
    # 0 Successfully ran script for case
    # 1 wvdial process already running
    # 2 wvdial was not terminated
    # 3 script was not ran with ADD or REMOVE events
    function getpid #get process id of running program
    pidof wvdial
    if [ "$?" = 0 ];
    then
    pid=`pidof wvdial`
    running=1
    else
    running=0
    fi
    function checkrun #check for a running copy of the program
    pidof wvdial
    if [ "$?" == "0" ];
    then
    running=1
    else
    running=0
    fi
    function killloop #a set of time kill commands to let the program exit gracefully
    #two terms, one int and one kill with suitable gaps
    getpid
    checkrun
    if [ "$running" = "0" ];
    then
    return
    fi
    kill $pid
    sleep 10
    checkrun
    if [ "$running" = "0" ];
    then
    return
    fi
    kill $pid
    sleep 10
    checkrun
    if [ "$running" = "0" ];
    then
    return
    fi
    kill -INT $pid
    sleep 5
    checkrun
    if [ "$running" = "0" ];
    then
    return
    fi
    kill -KILL $pid
    sleep 5
    checkrun
    if [ "$running" = "1" ];
    then
    exit 2 #process fails to die
    fi
    function getlaststatus
    if [ -e "/var/run/huawie" ];
    then
    last=`cat /var/run/huawie`
    else
    last=0
    fi
    if [ "$1" = "add" ];
    then
    getlaststatus
    if [ "$last" = "1" ];
    then
    exit 1
    fi
    echo 1 > /var/run/huawie #block future udev events
    getpid
    if [ "$running" = "1" ];
    then
    exit 1
    fi
    modprobe usbserial
    sleep 6 #modem init time
    wvdial &
    exit 0
    elif [ "$1" = "remove" ];
    then
    getlaststatus
    if [ "$last" = "2" ];
    then
    exit 0
    fi
    echo 2 > /var/run/huawie
    killloop
    exit 0
    else
    echo 3 > /var/run/huawie
    exit 3
    fi
    I'd appreciate any ideas, this one has me stumped
    Edit:
    Forgot to add that when I call the script manually it works like a charm.
    Last edited by adamd (2009-08-25 15:04:06)

    Hey
    I've got an interesting one here.
    I have scripted up a bash script to be triggered by a udev add event for my usb modem. As far as I can tell the udev event is firing correctly according to udevadm.
    ACTION=="add", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1003", RUN+="/bin/sh /usr/local/bin/huawei_key.sh add"
    ACTION=="remove", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1003", RUN+="/bin/sh /usr/local/bin/huawei_key.sh remove"
    And heres the code from the script
    #!/bin/bash
    #returns
    # 0 Successfully ran script for case
    # 1 wvdial process already running
    # 2 wvdial was not terminated
    # 3 script was not ran with ADD or REMOVE events
    function getpid #get process id of running program
    pidof wvdial
    if [ "$?" = 0 ];
    then
    pid=`pidof wvdial`
    running=1
    else
    running=0
    fi
    function checkrun #check for a running copy of the program
    pidof wvdial
    if [ "$?" == "0" ];
    then
    running=1
    else
    running=0
    fi
    function killloop #a set of time kill commands to let the program exit gracefully
    #two terms, one int and one kill with suitable gaps
    getpid
    checkrun
    if [ "$running" = "0" ];
    then
    return
    fi
    kill $pid
    sleep 10
    checkrun
    if [ "$running" = "0" ];
    then
    return
    fi
    kill $pid
    sleep 10
    checkrun
    if [ "$running" = "0" ];
    then
    return
    fi
    kill -INT $pid
    sleep 5
    checkrun
    if [ "$running" = "0" ];
    then
    return
    fi
    kill -KILL $pid
    sleep 5
    checkrun
    if [ "$running" = "1" ];
    then
    exit 2 #process fails to die
    fi
    function getlaststatus
    if [ -e "/var/run/huawie" ];
    then
    last=`cat /var/run/huawie`
    else
    last=0
    fi
    if [ "$1" = "add" ];
    then
    getlaststatus
    if [ "$last" = "1" ];
    then
    exit 1
    fi
    echo 1 > /var/run/huawie #block future udev events
    getpid
    if [ "$running" = "1" ];
    then
    exit 1
    fi
    modprobe usbserial
    sleep 6 #modem init time
    wvdial &
    exit 0
    elif [ "$1" = "remove" ];
    then
    getlaststatus
    if [ "$last" = "2" ];
    then
    exit 0
    fi
    echo 2 > /var/run/huawie
    killloop
    exit 0
    else
    echo 3 > /var/run/huawie
    exit 3
    fi
    I'd appreciate any ideas, this one has me stumped
    Edit:
    Forgot to add that when I call the script manually it works like a charm.
    Last edited by adamd (2009-08-25 15:04:06)

  • [SOLVED] How to get BASH scripts to recognize mounted partition paths?

    I don't understand how to get the bash script in the root partition to find the boot partition--both mounted at /mnt.
    I'm following the instructions on configuring "dm-crypt with LUKS" tutorial. The mkinitcpio command to generate the "initial ram disk environment" is producing an error while the system is booted from the install disk and the volumes it looks for are mounted at /mnt.
    #mkinitcpio -p linux
    ==> Building image from preset: /etc/mkinitcpio.d/linux/preset: 'default'
    -> -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux.img
    ==> ERROR: specified kernel image does not exist: `/boot/vmlinuz-linux'
    ==> Building image from preset: /etc/mkinitcpio.d/linux/preset: 'fallback'
    -> -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-fallback.img -S autodetect
    ==> ERROR: specified kernel image does not exist: `/boot/vmlinuz-linux`
    The script located in /mnt/root/etc can't find the "temporary kernel" located at /mnt/boot.
    Last edited by xtian (2013-09-17 22:01:35)

    And read them carefully, there should be no /mnt/root/etc/.
    There should be a /mnt/etc/ and a /mnt/boot and /mnt/root/ which is the root user's home directory, not the root filesystem (and of course /mnt/usr ...) - or if you decide to nest the whole thing deeper you could have /mnt/somename/etc and /mnt/somename/boot ...

  • Script to mount/unmount a USB thumb drive

    I am looking for an applescript to mount or unmount a USB thumb drive.
    I tried:
    tell application "Finder"
    do shell script "diskutil mount /dev/disk1"
    end tell
    This did not work for me

    I tested on a USB stick, no probs, I put my USB stick in a slot, waited for it to mount, ran the script using the "unmount first", then ran the "mount" second worked fine after that using the "unmount " part of the script, I found though that if I right clicked "eject" that the script would not mount the volume.
    You could try something as simple as the below maybe.
    tell application "Finder"
    eject "LEXAR MEDIA"
    end tell
    set _VolumeName to "LEXAR MEDIA"
    set deviceName to do shell script "diskutil list | grep \"" & _VolumeName & "\" | awk '{print $6}'"
    --do shell script "diskutil mountDisk /dev/" & deviceName --mount
    do shell script "diskutil unmountDisk /dev/" & deviceName --unmount
    Budgie

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

  • [SOLVED] advanced shell script for mount and unmount samba share

    Good morning guys,
    Today I've a very long question....
    Hope in your help....:
    I usually move from different network.
    For one of those I need to mount some share that are under an ActiveDirectory server.
    To do that I use samba.
    Especially I've made and use the below  shell script.
    I know that it's so stupid but I'm a very newbie:
    #!/bin/sh
    echo "This is a custom script for mount my citrix share"
    echo "Please insert user password (must a sudoer user)"
    echo " "
    sudo mount -t cifs -o username='myusername',password='mypassword' //host_ip/TsHome$/myusername /home/myuser/samba_share/TsHOME
    sudo mount -t cifs -o username='myusername',password='mypassword' "//host_ip/direction" /home/myuser/samba_share/direction
    echo " "
    read -p "Press ENTER key to close this terminal"
    exit
    As I say the script work but it's so crude...!
    I want/need to implement it whit the follow addictions:
    1. print a feedback on mount: somenthing like "TsHOME is now mounted" or "unable to mount TsHOME"
    2. check if the share are already mounted: to prevent accidentally multiple mount. If a share is already mounted I want to print something like "TsHOME is already mounted on /home/myuser/samba_share/TsHOME"
    3. ask for share password  (now it's in clear on script) - This is optinal
    4. un-mount the share before reboot or shutdown command. That because I've notice that If i reboot or shutdown without manually un-mount the share the step of unmounting network file system became very slow
    If it's no extremely difficult, can someone help me to write this script?
    I know that man exist but I'm not a programmer and it's so difficult for me approch it.
    Thank you in advance.
    Ale
    Last edited by Alexbit (2010-09-23 21:29:13)

    Thank you very (VERY) much!
    I've follow your information and.. it work!
    If can be usefull to other this is the complete script:
    #!/bin/sh
    echo "This is a custom script for mount citrix share"
    echo "****************************************"
    echo " "
    echo "Please insert domain password:"
    read -s mypassword
    echo " "
    echo "|checking mount state...in share are not mounted mount it!|"
    echo "+-------------------------------------------------------------------------+"
    if grep "TsHome" /etc/mtab &>/dev/null; then
    grep "TsHome" /etc/mtab | awk '{print "TsHome is already mounted on " $2}'
    else
    sudo mount -t cifs -o username='yourusername',password="$mypassword" //ipaddress/TsHome$ /home/Samba_share/TsHOME && echo "TsHOME is now mounted" || echo "unable to mount TsHOME"
    fi
    echo " "
    if grep "direction" /etc/mtab &>/dev/null; then
    grep "direction" /etc/mtab | awk '{print "direction is already mounted on " $2}'
    else
    sudo mount -t cifs -o username='yourusername',password="$mypassword" '//ipaddress/direction' /home/Samba_share/direction' && echo "direction pat is now mounted" || echo "unable to mount direction"
    fi
    echo " "
    if grep "Area" /etc/mtab &>/dev/null; then
    grep "Area" /etc/mtab | awk '{print "Area is already mounted on " $2}'
    else
    sudo mount -t cifs -o username='yourusername',password="$mypassword" '//ipaddress/Area' /home/Samba_share/Area && echo "Area is now mounted" || echo "unable to mount Area"
    fi
    echo " "
    echo "All DONE!"
    echo " "
    read -p "Press ENTER key to close this terminal"
    exit
    I don't really well understand what I've to put in rc.local.shutdown....
    I think somethings like:
    #!/bin/bash
    # /etc/rc.local.shutdown: Local shutdown script.
    echo "This is a custom script for UN-mount citrix share"
    echo "********************************************"
    echo " "
    echo "|check mount state: if mount then un-mount!|"
    echo "+-------------------------------------------------------+"
    echo " "
    if grep "TsHome" /etc/mtab &>/dev/null; then
    grep "TsHome" /etc/mtab | awk '{print "TsHome is NOT mounted -> going on..." $2}'
    else
    sudo umount /home/Samba_share/TsHOME && echo "TsHOME is now UN mounted" || echo "unable to UN-mount TsHOME"
    fi
    echo " "
    if grep "direction" /etc/mtab &>/dev/null; then
    grep "direction" /etc/mtab | awk '{print "direction is NOT mounted -> going on.." $2}'
    else
    sudo umount /home/Samba_share/direction && echo "direction is now UN mounted" || echo "unable to UN-mount direction pat"
    fi
    echo " "
    if grep "Area" /etc/mtab &>/dev/null; then
    grep "Area" /etc/mtab | awk '{print "Area is NOT mounted - Finished" $2}'
    else
    sudo umount /home/Samba_share/Area && echo "Area is now UN mounted" || echo "unable to UN-mount Area"
    fi
    echo " "
    echo "going shutdown"
    echo " "
    sleep 5
    I've try but it seems to ignore the IF statement... this is the output when ALL share are UNmounted:
    $ sh /etc/rc.local.shutdown
    This is a custom script for UN-mount citrix share
    |check mount state: if mount then un-mount!|
    +-------------------------------------------------------+
    umount: /home/Samba_share/TsHOME: not mounted
    unable to UN-mount TsHOME
    umount: /home/Samba_share/direction: not mounted
    unable to UN-mount direction
    umount: /home/Samba_share/Area: not mounted
    unable to UN-mount Area
    going shutdown
    Tomorrow I will test again when I'm at office.
    Meanwhile can you check if I made a macroscopic mistakes?
    Thank you again!
    Last edited by Alexbit (2010-09-23 17:34:49)

  • [SOLVED] XMMS2 media hotkeys, bash scripts

    Hi!
    For the really beginners of the XMMS2 users as me, should be a nice something like a guide/tutorial.
    Here is the bash scripts that might enchant functionality and be more useful for use of the media keys.
    For randomizing before any other action you can use even something like:
    xmms2 playlist shuffle ; xmms2 jump 1; xmms2 play
    # Just for dummies
    The Preview hotkey loop.
    From the begin of the playlist to the end of it when current is the first one being played:
    #!/bin/bash
    #Play the previews or first if end of the playlist
    if [ "XX"$(xmms2 prev | awk '{print $1}') == "XXServer" ] ; then
    if [ "XX"$(xmms2 jump $(xmms2 list | grep -i '/' |wc -l) | awk '{print $1}') == "XXServer" ] ; then
    xmms2 playlist list;
    echo The playlist is empty, please choose one from of the above ;
    echo or add a new songs to the playlist with a '"xmms2 add"';
    fi; fi;
    #It takes time to count to the last song in the playlist, longer it is more time it takes :(. I haven't found a better way yet.
    The Next hotkey loop.
    When the end of the playlist is reached then goto jumping to the first one song in the playlist:
    #!/bin/bash
    #Play the first song if in the end of the playlist
    if [ "XX"$(xmms2 next | awk '{print $1}') == "XXServer" ] ; then
    if [ "XX"$(xmms2 jump 1 | awk '{print $1}') == "XXServer" ] ; then
    xmms2 playlist list;
    echo The playlist is empty, please choose one from of the above ;
    echo or add a new songs to the playlist with a '"xmms2 add"';
    fi; fi;
    For the Play/Pause key:
    #!/bin/bash
    #For the single Play/Pause key
    GetStatus=$(xmms2 current | awk -F":" '{print $1}')
    #Any command line parameters to the script for randomizing of the playslist.
    if [ "S" != "S"$1 ] ; then
    xmms2 playlist shuffle
    fi;
    if [ "$GetStatus" == "Playing" ]; then xmms2 pause;fi
    if [ "$GetStatus" == "Paused" ]; then xmms2 play;fi
    if [ "$GetStatus" == "Stopped" ]; then
    xmms2 play
    GetStatus=$(xmms2 current | awk -F":" '{print $1}')
    if [ "$GetStatus" == "Stopped" ]; then
    xmms2 playlist list;
    echo The playlist is empty, please choose one from of the above ;
    echo or add a new songs to the playlist with a '"xmms2 add"';
    fi
    fi
    or you can use even xmms2 toggle command line for the play/pause hotkey.
    Turn On/Off repeat/loop of the playlist:
    #!/bin/bash
    GetStatus=$(xmms2 server config playlist.repeat_all )
    case $GetStatus in
    "playlist.repeat_all = 1") xmms2 server config playlist.repeat_all 0 ; sudo beep; echo is OFF ;;
    "playlist.repeat_all = 0") xmms2 server config playlist.repeat_all 1 ; sudo beep ; sudo beep ; echo is ON;;
    esac
    You can install beep but the beep has a problem, you can run it only as a root but a more danger way is to by pass this by adding the beep into /etc/sudoers , e.g. yourusername ALL=NOPASSWD: /usr/sbin/beep.  Be careful! It may expose your system for unwanted access to and do a harm. The best way is to find a better way for notification of changes.
    If someone has another script solutions for the multimedia hotkeys or media fun for XMMS2 then please share with us!
    Automation is power of the shell
    Notice
    The hotkey names of my Digital Media Keyboard 3000, but I think that it becomes more as a standard, it is just to get a faster access to the names.
    XF86AudioPlay, XF86AudioNext, XF86AudioPrev,XF86AudioStop
    XF86AudioMute (amixer -c 0 set Master toggle), *, (pactl set-sink-mute 0 toggle)
    XF86AudioRaiseVolume (amixer -c 0 set Master 3+), xmms2 server volume +3, (pactl set-sink-volume 0 +3%)
    XF86AudioLowerVolume (amixer -c 0 set Master 3-). xmms2 server volume -3, (pactl set-sink-volume 0 -- -3%)
    amixer = ALSA
    pactl = PulseAudio (0 is index of the sinks, you can see which you can use with pacmd list-sinks, marked with * is default)
    The other way to increase and decrease volumes is here.
    Change between ALSA and PulseAudio sound servers for XMMS2
    nyxmms2 server config output.plugin pulse
    nyxmms2 server config output.plugin alsa
    Otherwise you can use xev to retrieve the names of the supported keys by X server, as I know X server has a limitations to the 255 key numbers/keycodes. One more but less useful for GUI is showkey, just to know that it is also and always exists, with a great manual about the kbd keys.
    * To mute/unmute XMMS2 you can use xmms2 server volume 0 / xmms2 server volume 100 or for more advanced e.g. xmms2 server volume -c left 100/xmms2 server volume -c right 100 and combine with any keys you wish the way is best for you. I haven't found any way to make anything to remember status after mute/unmute of xmms2. Alias for the mute only is xmms2 mute. If you will find it before me please help .
    Here is one more guide for the BlackBox menu. I could not get xmms2 mlib loadall to work in Arch.
    In Arch you must use xmms2 playlist sort instead of xmms2 sort because it doesn't work otherwise.
    xmms2 playlist sort album
    xmms2 playlist sort title
    xmms2 playlist sort artis
    Last edited by Andy_Crowd (2014-10-18 11:34:45)

    Zariel wrote:
    i guess something like this?
    %optical ALL=(ALL) NOPASSWD: ALL
    I found the clues for this in the sudoers manual:
    handy   ALL = NOPASSWD: /sbin/umount /CDROM,\
                    /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM
    Which works in so far as now mounting no longer needs the password.
    Which leaves me with the problem of trying to understand how to get Worker to mount the optical drive on command.
    If I enter the bash command in the Terminal as follows:
    mount /mnt/dvd
    the media is mounted, after which I can push the button in Worker, which I have configured with:
    /mnt/dvd
    & the root list of the optical media is displayed in the active panel of Worker.
    I just haven't been able to get Worker to use "mount /mnt/dvd" yet, there will be a way, I wonder how long it will take me to find it? lol
    Last edited by handy (2008-11-19 06:48:09)

  • Mount an USB key under solaris 10 x86

    I've got a problem with solrais, I have got an USB key, and when I connect it to the computer, nothing is done.
    I want to know how I can mount my USB key.
    Willits

    Ok, I made a
    iostat -En And I obtained
    -bash-3.00# iostat -En
    c3t0d0           Soft Errors: 1 Hard Errors: 0 Transport Errors: 0
    Vendor: HP       Product: CD-Writer+ 9100b Revision: 1.07 Serial No:
    Size: 0.00GB <0 bytes>
    Media Error: 0 Device Not Ready: 0 No Device: 0 Recoverable: 0
    Illegal Request: 1 Predictive Failure Analysis: 0
    sd2              Soft Errors: 3 Hard Errors: 0 Transport Errors: 0
    Vendor: CREATIVE Product: MuVo TX FM       Revision: 1123 Serial No:
    Size: 0.00GB <0 bytes>
    Media Error: 0 Device Not Ready: 0 No Device: 0 Recoverable: 0
    Illegal Request: 3 Predictive Failure Analysis: 0
    c5t0d0           Soft Errors: 3 Hard Errors: 0 Transport Errors: 0
    Vendor: CREATIVE Product: MuVo TX FM       Revision: 1123 Serial No:
    Size: 0.26GB <258342912 bytes>
    Media Error: 0 Device Not Ready: 0 No Device: 0 Recoverable: 0
    Illegal Request: 3 Predictive Failure Analysis: 0
    If I understand it says that there is an illegal request ?
    This device name is c5t0d0, but inside of c5t0d0, there is:
    -bash-3.00# ls /vol/dev/dsk/c5t0d0/
    unknown_format
    -bash-3.00#
    woozat ?
    thx

  • Can you run a bash script on boot in single user mode

    Hey guys quick question.
    Is it possible to run a bash script on boot in single user mode.
    I can create a file and dump it on the root hd.
    Let's call it repair.
    I can then boot to single user mode and run it by typing /repair.
    But I want it to do it automatically.
    Every time I go into my machines that I clean for my job. I have to run sbin/fsck -fy
    Then I have to mount the drive and then remove all cache files, then reboot the machines.
    I would like to automate this by just holding command s and then moving to the next computer.
    There must be some sort of boot daemon somewhere.
    Please help.
    Sincerely,
    John

    Have you seen Applejack?
    http://applejack.sourceforge.net/
    It doesn't start automtically, but does cleanup.
    Robert

  • EXT4 errors while mounting a USB in initramfs on a specific computer

    Hi,
    I'm having trouble booting a newly installed Archlinux on a USB key on an old HP Compaq computer.
    I am getting EXT4 errors in the regular initramfs, but they blink really fast on the screen so I can't read them properly.
    It boots fine with the fallback initramfs, and dmesg shows that there are no problems while mounting.
    The system boots without any problem on both initramfs with QEMU on my Windows.
    My mkinitcpio.conf :
    # vim:set ft=sh
    # MODULES
    # The following modules are loaded before any boot hooks are
    # run. Advanced users may wish to specify all system modules
    # in this array. For instance:
    # MODULES="piix ide_disk reiserfs"
    MODULES=""
    # BINARIES
    # This setting includes any additional binaries a given user may
    # wish into the CPIO image. This is run last, so it may be used to
    # override the actual binaries included by a given hook
    # BINARIES are dependency parsed, so you may safely ignore libraries
    BINARIES=""
    # FILES
    # This setting is similar to BINARIES above, however, files are added
    # as-is and are not parsed in any way. This is useful for config files.
    FILES=""
    # HOOKS
    # This is the most important setting in this file. The HOOKS control the
    # modules and scripts added to the image, and what happens at boot time.
    # Order is important, and it is recommended that you do not change the
    # order in which HOOKS are added. Run 'mkinitcpio -H <hook name>' for
    # help on a given hook.
    # 'base' is _required_ unless you know precisely what you are doing.
    # 'udev' is _required_ in order to automatically load modules
    # 'filesystems' is _required_ unless you specify your fs modules in MODULES
    # Examples:
    ## This setup specifies all modules in the MODULES setting above.
    ## No raid, lvm2, or encrypted root is needed.
    # HOOKS="base"
    ## This setup will autodetect all modules for your system and should
    ## work as a sane default
    # HOOKS="base udev autodetect block filesystems"
    ## This setup will generate a 'full' image which supports most systems.
    ## No autodetection is done.
    # HOOKS="base udev block filesystems"
    ## This setup assembles a pata mdadm array with an encrypted root FS.
    ## Note: See 'mkinitcpio -H mdadm' for more information on raid devices.
    # HOOKS="base udev block mdadm encrypt filesystems"
    ## This setup loads an lvm2 volume group on a usb device.
    # HOOKS="base udev block lvm2 filesystems"
    ## NOTE: If you have /usr on a separate partition, you MUST include the
    # usr, fsck and shutdown hooks.
    HOOKS="base udev autodetect modconf block filesystems fsck keyboard"
    # COMPRESSION
    # Use this to compress the initramfs image. By default, gzip compression
    # is used. Use 'cat' to create an uncompressed image.
    #COMPRESSION="gzip"
    #COMPRESSION="bzip2"
    #COMPRESSION="lzma"
    #COMPRESSION="xz"
    #COMPRESSION="lzop"
    #COMPRESSION="lz4"
    # COMPRESSION_OPTIONS
    # Additional options for the compressor
    #COMPRESSION_OPTIONS=""
    I'm really puzzled about this, since I initially thought that the HP Compaq simply had problems with my USB key, but since it boots fine with the fallback initramfs, I think that it is the initramfs' fault, but it is the default one, so I currently have no clues about this.
    I've also checked the USB key multiple times with fsck, and that doesn't seem to be the cause of the problem.

    The thing is, the block module and the filesystem module are both loaded in my regular initramfs, and the presence of ext4 errors while mounting my USB key (it uses ext4) signifies that the system is actually using the right tool to do what it's supposed to.
    The system has been installed via VirtualBox so the autodetect module may have messed things up. Going to recreate an initramfs image without it.
    EDIT : It worked, sorry for bothering you guys, I could've found it sooner.
    Anyway, as a note for others, if you plan on installing on a USB key to use it on other computers, remove the autodetect module from the initramfs, otherwise the required modules won't always be there.
    Last edited by FreeSalad (2014-03-10 15:56:22)

  • Solaris 11 - run a simple BASH script on computer startup

    I need to have a simple BASH script run on my Solaris 11 machine automatically whenever the computer (re)starts. It should be run with root permissions and after the computer has fully booted. What is the easiest way to do that?
    Thank you
    Dusan

    Hi user9368043
    Yes, that should be right, and be intended this way.
    See /etc/rc3.d/README and the following part from smf(5):
    Legacy Startup Scripts
    Startup programs in the /etc/rc?.d directories are executed
    as part of the corresponding run-level milestone:
    /etc/rcS.d milestone/single-user:default
    /etc/rc2.d milestone/multi-user:default
    /etc/rc3.d milestone/multi-user-server:default
    Your question concerning upgrading to Solaris 11.1:
    In the Gnome menus, you should look for (and start)
    System --> Administration --> Update Manager
    Let it do its work. It will give you a new boot environment, containing Solaris 11.1. Possibly, you have to perform upgrading twice. With "beadm activate", see beadm(1M), you can go back to Solaris 11.0 whenever you want.
    "Local" parts of your zfs root pool, like /usr/local, home directories, /root, and so on, should be in separated file systems, and be mounted outside the root pool before upgrading. They are availlable then from any boot environment, and will not be duplicated. See more in zfs(1M), zpool(1M).
    I strongly recommend upgrading. Solaris 11.1 is great.

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

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

Maybe you are looking for

  • My Mail emails no longer show up once I click to highlight.

    I used to be able to click once on an email and then see the body of the email that fits in the window.  That no longer works.  Now I have to double click and open the entire email to get any view of it.  Thought it might have been some format change

  • Error message when ordered more items than it's available in stock.

    Hi again, I've noticed that on the Commerce Reference Store (CRS) if I order, let's say, 10 "branded belt black large" and there's only 5 available in stock my order goes through and the order's status is set to "Pending Merchant Action". Instead of

  • Enable autoarchiving for Oracle 10g RAC db

    Hello What are the steps to enable autoarchiving for Oracle 10g cluster database? It is currentrly in noarchivelog mode. Thank you, Yelena

  • Can I make the WLC send alarms to my email or a pager?

    I have two 4402-50's and I would love to have any alarms be sent to my email or a pager I have so I more closely can monitor the wireless network. Is this possible and where can I configure it? Thanks in Advance. David Beaver Internetwork Engineering

  • Need driver for modem ms-6949

    tried the MSI web site but they do not seem to list any modem drivers - just bought a couple of used pc's with these modems in them - any idea where I can find the driver ms-6946 s/n 6001969?  Thanks