[SOLVED]bash script

I had created a bash script which ensures that each of the applications has one instance. The problem is no applications are executed during startup. Here is my script:
if [ -z "ps aux | grep wmCalClock | head -n -1" ]
then
wmCalClock -b 100 -arial -tc cyan -bc black -e xterm &
fi
if [ -z "ps aux | grep wmfire | head -n -1" ]
then
wmfire -L1 -B1 -s0 -C2 -P fireload_temp &
fi
if [ -z "ps aux | grep wmcpuload | head -n -1" ]
then
wmcpuload -lc red -a 95 &
fi
if [ -z "ps aux | grep wmmemload | head -n -1" ]
then
wmmemload -lc red -am 95 &
fi
Last edited by heyya (2009-12-25 04:19:33)

Well, obviously not, as the string "ps aux | grep wmCalClock | head -n -1" is
never empty What you probably wanted to write is
"$(ps aux | grep wmCalClock | head -n -1)"
This will put the output of the script into the string, rather than taking the
command string itselft.

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)

  • (SOLVED) bash script header problem

    When i run this piece of code from the command line it works properly, but when i try and run it from a script it doesn't.
    It's supposed to be the beginning of a header
    printf "%*s\n" "$((COLUMNS))" " " | tr " " "=" ; printf "%*s\n" $((COLUMNS/2)) " Database " ; printf "%*s\n" $((COLUMNS)) " " | tr " " "="
    Any help would be appreciated, thanks
    Last edited by unilx (2012-04-23 23:58:53)

    COLUMNS is not defined in a normal script.
    Now to find a solution ...
    Edit: does "sourcing" the script work from an interactive session?
    e.g.
    ~$ ./test.sh
    ./test.sh: line 2: 0: command not found
    $ . test.sh
    bash: 89: command not found
    where test.sh has only
    #!/bin/bash
    $((COLUMNS))
    Edit2:
    try
    WIDTH=`stty size | cut -d" " -f2`
    then use $WIDTH instead of $((COLUMNS))
    Last edited by Trilby (2012-04-23 23:16:22)

  • [Solved] - Bash scripting - variable question.

    Hi!
    I have a little problem, I want to get data from a variable, but the variable-name that I want to
    get the data from is constructed by another variable.
    Let me explain with a little non-working example:
    test1="data1"
    test2="data2"
    test3="data3"
    for i in {1..3};do
    echo value=$[test$i];done
    I want to get the output of this code to be:
    value=data1
    value=data2
    value=data3
    and I cannot use arrays in the script I'm working on. I know how to do this in other languages
    but cannot figure it out how to do it in bash.
    Please help!
    Last edited by JSHN (2009-10-06 19:55:15)

    you need the eval command to finish how you started:
    eval echo value=\$test$i
    Otherwise, use bash arrays:
    test=('data1' 'data2' 'data3')
    for i in $(seq 0 2);do # zero-based...
    echo value=${test[$i]}
    done
    ninja-edit to remove the comma's in the array
    Last edited by klixon (2009-10-06 19:27:03)

  • [SOLVED] Bash Script checking for mail

    I have come up with this forsaken script...
    #!/bin/bash
    while :
    do
    NEWMAIL=$(curl -su "You'd wish." https://mail.google.com/mail/feed/atom | grep fullcount | cut -d ">" -f 2 | cut -d "<" -f 1)
    echo $NEWMAIL
    notify-send "Gmail" "You have $NEWMAIL new mails!"
    sleep 10s
    done
    It does get the number of new mails perfectly fine - I'm sure there is a better method with cut... -, and it echos the number, but notify-send does not seem to work. From what I've read I need to set the environmental variable or something like that. Yeah, no clue. Any hint is appreciated.
    Last edited by ThunderRush (2013-02-05 14:38:15)

    I tried that aesiris, of course with some gnome things, but it did not work either.
    And for jason: It's okay, thank you again for your help.
    I will see what else I can do, and will post a solution if I find one - which I doubt.
    What other alternatives to notify-send are there? Not a whole popup, but something more subtle?
    #EDIT
    As always, my own stupidity.
    Since I had absolutely no right set on the file, since the password is there in clear text, ist had the Permissions 111.
    But - gnome did not belong to my root.
    ps aux | grep gnome
    And I always started it as sudo, as root. So I changed the ownership to my user...
    sudo chown thunderuser gmailcheck
    and set the rights to 500. So I can execute and read it.
    And it finally worked. Thanks again.
    Last edited by ThunderRush (2013-02-05 14:37:53)

  • [Solved] Bash scripting and sed substitution

    Hello!
    I am writing a script in order to substitute strings from one array to another one in texts.
    For only one case it is working as the following :
    sed '/ā/s/\(.*\)ā\(.*\)/\1a\21/g' temp.txt > temp2.txt
    which converts ā in a word by the same word with a normal "a" and the number 1 at the end of the word (māng > mang1)
    For many cases i've made some arrays and containing the rules in a srcipt file :
    # These are the 4 databases containing the strings that are suposed to be replaced
    data1[1]=ā
    data1[2]=ē
    data1[3]=ī
    data1[4]=ō
    data1[5]=ū
    data1[6]=ǖ
    data2[7]=á
    data2[8]=é
    data2[9]=í
    data2[10]=ó
    data2[11]=ú
    data2[12]=ǘ
    data3[13]=ǎ
    data3[14]=ě
    data3[15]=ǐ
    data3[16]=ǒ
    data3[17]=ǔ
    data3[18]=ǚ
    data4[19]=à
    data4[20]=è
    data4[21]=ì
    data4[22]=ò
    data4[23]=ù
    data4[24]=ǜ
    # This is the data base of output correspondances
    data[1]=a
    data[2]=e
    data[3]=i
    data[4]=o
    data[5]=u
    data[6]=ü
    count=1
    for base in {1..4} # For each database
    do
    for case in {1..6} # For each case
    do
    sed "/${data${base}[$count]}/s/\(.*\)${data${base}[$count]}\(.*\)/\1${data[$case]}\2$base/g" temp.txt > temp2.txt
    let "count+=1" #go to the next case in the database
    cat temp2.txt > temp.txt
    done
    done
    I have a substitution issue in the sed line. In fact I am trying to make a double substitution and it doesn't works.
    Like the first substitution ${data${base}[$count]} make 3 substitutions at a time… but I can't make it to work.
    In that case it would give me, for instance, the string contained in data2[3].
    I hope you understand what i mean. And i'd like to know how to deal with that substitution issue if you have an idea…
    Last edited by jiehong (2010-09-26 07:49:25)

    I've implemented what Procyon told in the part 2 and it's working with a small adaptation, which is great!!
    I've just an issue now because the number will go right after a word but at the end of the ligne… even if words are spaced by a space… like :
    hǎo
    hào
    wō wó wǒ wò wo
    become :
    hao3
    hao4
    wo wo wo wo wo1234
    my sed ligne is now :
    sed "/$(eval echo \$\{data$base[$count]\})/s/\(.*\)$(eval echo \$\{data$base[$count]\})\(.*\)/\1${data[$case]}\2$base/g" temp.txt > temp2.txt
    Last edited by jiehong (2010-09-25 20:27:57)

  • [SOLVED] Bash scripting - figure out how much you've downloaded

    Hi
    How would I aproach displaying how much (in mb/kb/gb whatever) I've downloaded?
    Thanks
    Last edited by valvet (2010-11-04 13:10:13)

    There's also http://www.archlinux.org/packages/?sort … =&limit=50
    [karol@black ~]$ vnstat -d
    eth0 / daily
    day rx | tx | total | avg. rate
    ------------------------+-------------+-------------+---------------
    10/02/10 525.89 MiB | 28.77 MiB | 554.66 MiB | 52.59 kbit/s
    10/03/10 850.30 MiB | 20.01 GiB | 20.84 GiB | 2.02 Mbit/s
    10/04/10 353.02 MiB | 20.26 MiB | 373.28 MiB | 35.39 kbit/s
    10/05/10 601.78 MiB | 42.41 MiB | 644.19 MiB | 61.08 kbit/s
    10/06/10 471.46 MiB | 26.29 MiB | 497.75 MiB | 47.19 kbit/s
    10/07/10 312.86 MiB | 15.24 MiB | 328.10 MiB | 31.11 kbit/s
    10/08/10 250.51 MiB | 13.85 MiB | 264.36 MiB | 25.07 kbit/s
    10/09/10 456.25 MiB | 22.86 MiB | 479.11 MiB | 45.43 kbit/s
    10/10/10 1.21 GiB | 43.15 MiB | 1.25 GiB | 121.82 kbit/s
    10/11/10 442.58 MiB | 21.45 MiB | 464.02 MiB | 44.00 kbit/s
    10/12/10 757.99 MiB | 33.45 MiB | 791.44 MiB | 75.04 kbit/s
    10/13/10 274.19 MiB | 18.22 MiB | 292.41 MiB | 27.72 kbit/s
    10/14/10 1.11 GiB | 48.94 MiB | 1.16 GiB | 112.59 kbit/s
    10/15/10 1.08 GiB | 42.71 MiB | 1.12 GiB | 108.95 kbit/s
    10/16/10 921.70 MiB | 32.01 MiB | 953.71 MiB | 90.43 kbit/s
    10/17/10 929.25 MiB | 37.68 MiB | 966.94 MiB | 91.68 kbit/s
    10/18/10 1.78 GiB | 73.96 MiB | 1.85 GiB | 179.53 kbit/s
    10/19/10 391.16 MiB | 19.23 MiB | 410.39 MiB | 38.91 kbit/s
    10/20/10 1.30 GiB | 42.81 MiB | 1.34 GiB | 130.33 kbit/s
    10/21/10 2.67 GiB | 77.57 MiB | 2.75 GiB | 267.06 kbit/s
    10/22/10 1.17 GiB | 36.96 MiB | 1.21 GiB | 117.29 kbit/s
    10/23/10 3.91 GiB | 104.04 MiB | 4.01 GiB | 389.56 kbit/s
    10/24/10 4.43 GiB | 124.12 MiB | 4.55 GiB | 441.50 kbit/s
    10/25/10 2.48 GiB | 71.18 MiB | 2.55 GiB | 247.22 kbit/s
    10/26/10 7.25 GiB | 146.55 MiB | 7.39 GiB | 717.75 kbit/s
    10/27/10 0.98 GiB | 35.87 MiB | 1.02 GiB | 98.78 kbit/s
    10/28/10 1.22 MiB | 599 KiB | 1.81 MiB | 0.17 kbit/s
    11/02/10 1.77 GiB | 30.93 MiB | 1.80 GiB | 174.33 kbit/s
    11/03/10 961.69 MiB | 44.55 MiB | 0.98 GiB | 95.41 kbit/s
    11/04/10 1.09 GiB | 44.35 MiB | 1.13 GiB | 170.49 kbit/s
    ------------------------+-------------+-------------+---------------
    estimated 1.69 GiB | 68 MiB | 1.76 GiB |
    [karol@black ~]$ vnstat -m
    eth0 / monthly
    month rx | tx | total | avg. rate
    ------------------------+-------------+-------------+---------------
    Feb '10 66.99 GiB | 4.72 GiB | 71.71 GiB | 248.65 kbit/s
    Mar '10 31.77 GiB | 2.68 GiB | 34.45 GiB | 107.89 kbit/s
    Apr '10 28.77 GiB | 2.50 GiB | 31.26 GiB | 101.18 kbit/s
    May '10 6.38 GiB | 682.79 MiB | 7.05 GiB | 22.08 kbit/s
    Jun '10 6.10 GiB | 347.45 MiB | 6.44 GiB | 20.83 kbit/s
    Jul '10 41.02 GiB | 1.73 GiB | 42.75 GiB | 133.89 kbit/s
    Aug '10 49.31 GiB | 2.91 GiB | 52.21 GiB | 163.52 kbit/s
    Sep '10 14.49 GiB | 939.38 MiB | 15.40 GiB | 49.85 kbit/s
    Oct '10 41.93 GiB | 21.36 GiB | 63.29 GiB | 198.21 kbit/s
    Nov '10 3.79 GiB | 119.83 MiB | 3.91 GiB | 104.14 kbit/s
    ------------------------+-------------+-------------+---------------
    estimated 31.21 GiB | 979 MiB | 32.17 GiB |

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

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

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

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

  • Simple bash script to add a '-' [Solved]

    I need to write a small bash script to add a '-' to each line in a file before displaying via conky!
    Todo
    - Get Milk
    - Buy Food
    - Pay Bills
    Currently I use
    TEXT
    Todo
    ${hr}
    ${head /home/mrgreen/.stuffigottado.txt 30 20}
    In .conkyrc but have to add '-' each time I edit .stuffigottado.txt
    Thanks in advance....

    Cerebral wrote:
    To filter out blank lines, you could just modify the awk command:
    ${exec awk '!/^$/ { print "-", $_ }' stuffigottado.txt}
    very nice; awk and grep: two commands that never cease to amaze me.

  • Multiarchive RAR bash script (SOLVED)

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

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

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

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

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

  • [solved] Segmentation fault with bash script

    I have a bash script that checks if it has to do something, if not it sleeps 15 secs and checks again. It works great except that after ~6hrs of just checking and sleeping it seg faults. I upped the stack limit with ulimit -s and it goes ~12hrs before it seg faults. I have a similar script that I have been using for ages that works for 24hrs no problem and I can't pinpoint where the problem is.
    The check it does is to see if a file exists, if it's empty and if not, read the first line of a file and do some date comparisons. It doesn't matter if the file is empty or not the seg fault always happens.
    Here's the seg fault causing script - it starts at the bottom
    #!/bin/bash
    # User defines
    declare -i DVB_DEVICE_NUM="0"
    declare CHANNELS_CONF="${HOME}/Mychannels.conf"
    declare SAVE_FOLDER="${HOME}/TV/tele"
    declare SCHED_FILE="$HOME/.sched-tv"
    declare ZAP_COMMAND="tzap"
    declare -i SLEEP=15
    # Program defines
    declare -i DAY="0"
    declare -i START="0"
    declare -i FINISH="0"
    declare CHAN="0"
    declare NAME="0"
    declare -i MINUTES="0"
    declare -i REC_START="0"
    declare -i REC_HOURS="0"
    declare -i REC_MINS="0"
    declare -i howlong="0"
    declare -i PIDOF_AZAP=0
    declare -i PIDOF_CAT=0
    red='\033[1;31m'
    green='\033[1;32m'
    yell='\033[1;33m'
    cyan='\033[1;36m'
    white='\033[1;37m'
    reset='\033[0m'
    function remove_entry {
    if [ "$NAME" == "" ]; then
    sed "/$DAY $START $FINISH $CHAN/d" $SCHED_FILE > /tmp/dummy
    else
    sed "/$DAY $START $FINISH $CHAN $NAME/d" $SCHED_FILE > /tmp/dummy
    fi
    mv /tmp/dummy $SCHED_FILE
    function record_entry {
    ${ZAP_COMMAND} -a ${DVB_DEVICE_NUM} -f ${DVB_DEVICE_NUM} -d ${DVB_DEVICE_NUM} \
    -c $CHANNELS_CONF -r ${CHAN} >/dev/null 2>&1 &
    PIDOF_AZAP=$!
    if [ "$PIDOF_AZAP" == "" ]; then
    printf "$red\tError starting ${ZAP_COMMAND}.\n\tFAILED: $CHAN $START\n"
    remove_entry
    exit 1
    fi
    printf "$green\tSET CHANNEL$cyan ${CHAN}\n"
    REC_MINS=$((${START}%100))
    REC_HOURS=0
    MINUTES=0
    REC_START=$(($START-$REC_MINS))
    while [ $((${REC_START}+${REC_HOURS}+${REC_MINS})) -lt $FINISH ]; do
    ((REC_MINS++))
    ((MINUTES++))
    if [ ${REC_MINS} -ge 60 ]; then
    REC_MINS=0
    ((REC_HOURS+=100))
    fi
    done
    if [ "$NAME" == "" ]; then
    declare FILE_NAME="${SAVE_FOLDER}/TV-`date +%Y%m%d-%H%M`-ch.${CHAN}-${MINUTES}.min.mpg"
    else
    declare FILE_NAME="${SAVE_FOLDER}/TV-${NAME}-${MINUTES}.min.mpg"
    fi
    dd if=/dev/dvb/adapter${DVB_DEVICE_NUM}/dvr${DVB_DEVICE_NUM} \
    of=${FILE_NAME} conv=noerror &
    PIDOF_CAT=$!
    if (( ${PIDOF_CAT} == 0 )); then
    printf "$red\tError Starting Recording.\n\t/dev/dvb/adapter${DVB_DEVICE_NUM}/dvr${DVB_DEVICE_NUM} Unavailable\n"
    kill ${PIDOF_AZAP}
    remove_entry
    exit 1
    fi
    printf "$yell\tRECORDING TO :$cyan ${FILE_NAME}\n"
    sleep ${MINUTES}m
    kill ${PIDOF_CAT} && wait ${PIDOF_CAT} 2> /dev/null
    # pkill $ZAP_COMMAND # && wait ${PIDOF_AZAP} 2> /dev/null
    kill ${PIDOF_AZAP} && wait ${PIDOF_AZAP} 2> /dev/null
    printf "$yell\tFINISHED REC :$cyan ${FILE_NAME}\n$reset"
    remove_entry
    waiting 1
    function check_action {
    [ -e "$SCHED_FILE" ] || waiting $SLEEP
    [ "`cat $SCHED_FILE`" == "" ] && waiting $SLEEP
    DAY="0"; START="0"; FINISH="0"; CHAN="0"; NAME="0"
    TODAY=`date +%Y%m%d`
    NOW=`date +%k%M`
    while read -r DAY START FINISH CHAN NAME; do
    #printf "$DAY $START $FINISH $CHAN $NAME\n"
    break
    done < $SCHED_FILE
    if [ $DAY == $TODAY ] && [ $START -lt $NOW ]; then
    printf "$red\tOld Entry : Removing $CHAN $START\n"
    remove_entry
    waiting 1
    fi
    if [ $DAY == $TODAY ] && [ $START == $NOW ]; then
    record_entry
    else
    waiting $SLEEP
    fi
    function waiting {
    howlong=$1
    sleep $howlong && check_action
    check_action
    exit 0
    And the script that has been working fine 24hrs at a time
    #!/bin/bash
    echo alarm uses a twelve hour clock
    echo Type the time for the alarm to sound as 00-00-?m
    echo e.g. 05-35-pm for 5:35pm :: 05-35-am for 5:35am
    read TIME
    function play {
    A="$(date +%I-%M-%P)"
    if [ $A = $TIME ]; then
    for i in {1..10}; do
    $(aplay -c 1 /home/$USER/alarm/chime.wav); done
    exit
    else
    wait
    fi
    function wait {
    sleep 15 && play
    play
    I was hoping to have this script idling away in screen with rtorrent, always ready to do something if need be but that's not going to happen unless I can get a clue on what part of the script I need to change to not hit any limits. My websearches are failing me on this...
    Last edited by moetunes (2012-06-24 21:41:52)

    Thanks falconindy. I changed to using a while loop.
    #!/bin/bash
    set -o nounset
    shopt -s huponexit
    # User defines
    declare -i DVB_DEVICE_NUM="0"
    declare CHANNELS_CONF="${HOME}/Mychannels.conf"
    declare SAVE_FOLDER="${HOME}/TV/tele"
    declare SCHED_FILE="$HOME/.sched-tv"
    declare ZAP_COMMAND="tzap"
    declare -i SLEEP=15
    # Program defines
    declare -i DAY="0"
    declare -i START="0"
    declare -i FINISH="0"
    declare CHAN="0"
    declare NAME="0"
    declare -i MINUTES="0"
    declare -i REC_START="0"
    declare -i REC_HOURS="0"
    declare -i REC_MINS="0"
    declare -i howlong=$SLEEP
    declare -i PIDOF_AZAP=0
    declare -i PIDOF_CAT=0
    red='\033[1;31m'
    green='\033[1;32m'
    yell='\033[1;33m'
    cyan='\033[1;36m'
    white='\033[1;37m'
    reset='\033[0m'
    function remove_entry {
    if [ "$NAME" == "" ]; then
    sed "/$DAY $START $FINISH $CHAN/d" $SCHED_FILE > /tmp/dummy
    else
    sed "/$DAY $START $FINISH $CHAN $NAME/d" $SCHED_FILE > /tmp/dummy
    fi
    mv /tmp/dummy $SCHED_FILE
    function record_entry {
    ${ZAP_COMMAND} -a ${DVB_DEVICE_NUM} -f ${DVB_DEVICE_NUM} -d ${DVB_DEVICE_NUM} \
    -c $CHANNELS_CONF -r ${CHAN} >/dev/null 2>&1 &
    PIDOF_AZAP=$!
    if [ "$PIDOF_AZAP" == "" ]; then
    printf "$red\tError starting ${ZAP_COMMAND}.\n\tFAILED: $CHAN $START\n"
    remove_entry
    exit 1
    fi
    printf "$green\tSET CHANNEL$cyan ${CHAN}\n"
    REC_MINS=$((${START}%100))
    REC_HOURS=0
    MINUTES=0
    REC_START=$(($START-$REC_MINS))
    while [ $((${REC_START}+${REC_HOURS}+${REC_MINS})) -lt $FINISH ]; do
    ((REC_MINS++))
    ((MINUTES++))
    if [ ${REC_MINS} -ge 60 ]; then
    REC_MINS=0
    ((REC_HOURS+=100))
    fi
    done
    if [ "$NAME" == "" ]; then
    declare FILE_NAME="${SAVE_FOLDER}/TV-`date +%Y%m%d-%H%M`-ch.${CHAN}-${MINUTES}.min.mpg"
    else
    declare FILE_NAME="${SAVE_FOLDER}/TV-${NAME}-${MINUTES}.min.mpg"
    fi
    dd if=/dev/dvb/adapter${DVB_DEVICE_NUM}/dvr${DVB_DEVICE_NUM} \
    of=${FILE_NAME} conv=noerror &
    PIDOF_CAT=$!
    if (( ${PIDOF_CAT} == 0 )); then
    printf "$red\tError Starting Recording.\n\t/dev/dvb/adapter${DVB_DEVICE_NUM}/dvr${DVB_DEVICE_NUM} Unavailable\n"
    kill ${PIDOF_AZAP}
    remove_entry
    exit 1
    fi
    printf "$yell\tRECORDING TO :$cyan ${FILE_NAME}\n"
    sleep ${MINUTES}m
    kill ${PIDOF_CAT} && wait ${PIDOF_CAT} 2> /dev/null
    # pkill $ZAP_COMMAND # && wait ${PIDOF_AZAP} 2> /dev/null
    kill ${PIDOF_AZAP} && wait ${PIDOF_AZAP} 2> /dev/null
    printf "$yell\tFINISHED REC :$cyan ${FILE_NAME}\n$reset"
    remove_entry
    while true; do
    sleep $howlong
    howlong=$SLEEP
    [ -e "$SCHED_FILE" ] || continue
    [ "`cat $SCHED_FILE`" == "" ] && continue
    TODAY=`date +%Y%m%d`
    NOW=`date +%k%M`
    while read -r DAY START FINISH CHAN NAME; do
    #printf "$DAY $START $FINISH $CHAN $NAME\n"
    break
    done < $SCHED_FILE
    if [ $DAY == $TODAY ] && [ $START -lt $NOW ]; then
    printf "$red\tOld Entry : Removing $CHAN $START\n"
    remove_entry
    howlong=1
    continue
    fi
    if [ $DAY == $TODAY ] && [ $START == $NOW ]; then
    record_entry
    fi
    done
    exit 0
    I think that should be ok now.

  • [solved]Need help with a bash script for MOC conky artwork.

    I need some help with a bash script for displaying artwork from MOC.
    Music folders have a file called 'front.jpg' in them, so I need to pull the current directory from MOCP and then display the 'front.jpg' file in conky.
    mocp -Q %file
    gives me the current file playing, but I need the directory (perhaps some way to use only everything after the last  '/'?)
    A point in the right direction would be appreciated.
    thanks, d
    Last edited by dgz (2013-08-29 21:24:28)

    Xyne wrote:
    You should also quote the variables and output in double quotes to make the code robust, e.g.
    filename="$(mocp -Q %file)"
    dirname="${filename%/*}"
    cp "$dirname"/front.jpg ~/backup/art.jpg
    Without the quotes, whitespace will break the code. Even if you don't expect whitespace in any of the paths, it's still good coding practice to include the quotes imo.
    thanks for the tip.
    here it is, anyhow:
    #!/bin/bash
    filename=$(mocp -Q %file)
    dirname=${filename%/*}
    cp ${dirname}/front.jpg ~/backup/art.jpg
    then in conky:
    $alignr${execi 30 ~/bin/artc}${image ~/backup/art.jpg -s 100x100 -p -3,60}
    thanks for the help.
    Last edited by dgz (2013-08-29 21:26:32)

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

Maybe you are looking for