[SOLVED] FFMPEG appears to be trashing bash script variables

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

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

Similar Messages

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

  • Conky doesn't display bash-script variables (array)

    I've been playing around with Conky and a bash script of mine. Unfortunately Conky displays only static text and not the array-variables in my script.
    In my script:
    ...some code here...
    echo "Static text: ${Variable[1]}"
    In my conkyrc:
    ...some code here...
    ${exec ~/Test/test.sh}
    The result is: "Static text: ". When running the script from the command line everything is fine. I've also tried with exec, execi, execp, texeci to no avail. Any ideas?
    Edit: I had to be more specific.
    Last edited by chilebiker (2009-10-06 03:30:20)

    Try echo -n "Static text: ${Variable[1]}"

  • [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] Conky Mail Notification using a Bash Script

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

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

  • [solved] Measuring how much time a bash function takes to run?

    Hi there,
    a (hopefully) simple question for the bash gods out there :)
    Lets say i have a script looking like this:
    #!/bin/bash
    some_function() {
    doing something
    some_function
    How can i measure the time (preferably in human-readable form: minutes or even hours) the bash function takes for a run?
    I know about "time", but i want to do it directly inside the script...
    Google tells me nothing, apart from one site where i have to pay for a solution :/
    Thanks for any suggestions
    Jan
    Last edited by funkyou (2008-09-01 13:21:04)

    iphitus@laptop:~$ sh test.sh
    Hi
    Bye
    real 0m10.002s
    user 0m0.000s
    sys 0m0.003s
    iphitus@laptop:~$ cat test.sh
    somefunc(){
    echo "Hi"
    sleep 10
    echo "Bye"
    time somefunc
    Time appears to work within bash scripts too

  • [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] Selecting folder span in bash script

    Hey all,
    Recently, I decided to get an audio-book from Audible and discovered the mp3 player they advertise about is only for ipods.  This meant that the only legit way to transfer it to my mp3 player (an .aa file/DRM protected) was to use iTunes burn it to multiple cds.  Doingthis had the book span 14 disks and now I'm trying to put it back together.  I used a great program called 'ripit' to rip the files back to Linux and now I'm faced with the task of concatenating the files back together again.  Ripit ripped the disks to 14 separate folders:
    Unknown Artist - Unknown Album
    Unknown Artist - Unknown Album 1
    Unknown Artist - Unknown Album 2
    Unknown Artist - Unknown Album 13
    To get these to appear in correct order I first rename the first album:
    mv Unknown\ Artist\ -\ Unknown\ Album/ Unknown\ Artist\ -\ Unknown\ Album\ 0
    replaced white spaces with hyphens (necessary for the next step):
    find -name "* *" -type d | rename 's/ /-/g'
    Zeropad the numbers to show in the right order (using this persons excellent script - http://www.walkingrandomly.com/?p=2850):
    for i in *; do mv "$i" $(zeropad "$i"); done
    #!/bin/bash
    # zeropad
    # Filter that will take input with basic numbering and zero pad it (i.e. file002)
    # e.g. mv file1.png `$(zeropad) $i`
    # http://www.walkingrandomly.com/?p=2850
    num=`expr match "$1" '[^0-9]*\([0-9]\+\).*'`
    paddednum=`printf "%03d" $num`
    echo ${1/$num/$paddednum}
    So now my directories look like this:
    Unknown-Artist---Unknown-Album-000
    Unknown-Artist---Unknown-Album-001
    Unknown-Artist---Unknown-Album-013
    Now I'm trying to create a bash script that will put this mp3s back together again.  mp3cat is the right utility to do this so I need to create a bash script that I can tell what folders to use to put them together.  Originally the book from Audible came in three parts:
    SK...part1.aa
    SK...part2.aa
    SK...part3.aa
    part 1 covers directories 000 to 004, part 2 005 to 008, part 3 009 to 013.  The script though I'd like to be generic (to be able to accept input if I decided to ever do this again).  Here it is thus as I have it so far figured out:
    echo "Join multiple mp3s from which folders?"
    echo -n "First folder number [0xx]: "
    read first_folder
    echo -n " to folder number [0xx]: "
    read final_folder
    echo -n " Name of file [name].mp3: "
    read filename
    for f in Unknown-Artist---Unknown-Album-[$first_folder-$final_folder]; do
    cat "$f"/*.mp3 | mp3cat - - > "$filename".mp3
    done
    I'd like to be able to input which directory to begin with and then input which directory to end with.  My use of [$first_folder-$final_folder] here shows my limited use of bash and I know that this this is only going to work for a single digit.  Any ideas what I can do here?
    Last edited by Gen2ly (2011-09-19 02:25:04)

    If there are spaces in the filenames then using globbing won't change anything. When stored in an array the new elements are split at spaces. This has the same problem as using ls. edit: ok so, "newer" versions of bash won't split the elements at spaces but the spaces still screw up when the array is expanded to command arguments.
    As usual all problems of existence are just a primitive form of bending. I mean, sorting! Crap. No need to remove the spaces and rename everything. sort and awk like spaces.
    # Must... have... number!
    mv "Unknown Artist - Unknown Album" "Unknown Artist - Unknown Album 0" \
    2>/dev/null
    # Sort & awk read as many number chars as possible, then give up.
    # ./Unknown Artist - Unknown Album 1/Track 1.mp3
    # (Fields) 6_/*^^^^^^ *^^^^\_7
    find . -name '*.mp3' | sort -n -k6 -k7 | \
    # $6+0 coerces $6 into a number.
    awk -v beg="$1" -v end="$2" '$6+0 >= beg && $6+0 <= end' |
    # Use NULL chars instead of newlines to make xargs happy.
    tr '\n' '\0' | xargs -0 cat
    # Without NULL chars and -0, xargs splits on lines AND spaces. Bad.
    Instead of changing the data (paths) to make it sort lexicographically, I simply sorted the data explicitly. Two args: beginning number and ending number. It's probably too late, since you renamed everything but maybe you can use the tr | xargs trick. Avoid using bash arrays or get rid of the spaces in the filenames.
    Last edited by juster (2011-09-18 13:02:59)

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

Maybe you are looking for

  • How to change Availability check (MTVFP) in sales order

    Hi, is it possible to change the Availability check on an material in an sales order? Some material have the value KP (no check) of Availability check in table MARC. If we use this material in sales orders somtimes we want change the Availability che

  • How do i make a navigation bar for all pages

    Hi friends ! I want the same navigation bar to appear on all the web pages of my website. (As these are the common things that all the webpages will have). But I didn't find any option to use the navigation bar as a template. Will I have to copy and

  • NOKIA N79 BACKLIGHT PROBLEM

    I HAVE A PROBLEM WITH MY NOKIA N79, WHEN I PLAY GAME AND BRING THE SCREEN IN STANDBY MODE BY PUTTING THE GAME IN BACKGRUNG AFTERSOME WHILE MY MOBILE'S BACKLIGHT SCREEN DOESNT WORK PROPERLY, EVEN IF I OPEN KEYPAD LOCK & PRESSES BUTTONS ITS LIGHT DOESN

  • Single inbound file - XI - Multiple IDOCs in SAP

    Hi XI pros, my file input file has very simple structure of header and item: H L L L Header has 2 fields snd item has 3 fields which I need to map to IDOC and post simple MM document in SAP. Mapping itself is very easy. I need to create separate IDOC

  • Pass word for airport

    i can not remember my password for my wifi