Escaping filename in bash script

What is the easiest way to escape a file name in a bash script? Any legal character can be in the name.
bash code:
fileCheckSum=$( cat "${theFilePath}" "${theFilePath}/rsrc" | md5 )
I thought that I escaped the filenames already. Guess not.
/Users/mac/cons/see/file name varients/funies '2/file 4
cat: /Users/mac/cons/see/file name varients/funies '2/file 4: No such file or directory
cat: /Users/mac/cons/see/file name varients/funies '2/file 4/rsrc: No such file or directory
Robert

For my driver download/reboot script I use a small program available in the ncftp package off of SunFreeware called ncftpget. It's takes a URL containing username, password, hostname, and path as the commandline argument and gets the file.
ftp://ftp.sunfreeware.com/pub/freeware/sparc/8/ncftp-3.0.1-sol8-sparc-local.gz
Hope that helps....
-M

Similar Messages

  • Bash script to trim all filenames with special characters recursively?

    Hi,
    I have a 30 GB directory full of data I recovered from a friend's laptop after her Windows XP crashed. I'd like to burn that data, but I can't, because many of the filenames contain weird characters (spaces, accents, things even worse that my XTerm displays as inverted question marks). So, mkisofs exits with an error.
    I'd like to clean that mess up, but it would take months to do that manually. Well, I only know a very little Bash, but I think this problem is already too heavy for my modest knowledge. Here's the problem:
    - check the contents of directory ~/backup recursively
    - find files whose filenames contain characters other than [A-Za-z0-9] and then maybe "-" and "_" and ".".
    - replace these characters either by an "_" or just erase them
    Now how would I translate that into a little Bash script?
    Cheers...

    Heyyyyy... nice idea

  • Passing Files/Folders to BASH script...

    I'm trying to pass a list of files and folders selected in finder to a bash script so that I can use VLC to perform some transcoding and concatenation on them.
    I'm using "Get Selected Finder Items" to pass the "Files/Folders" output "As Arguments" to my script.
    Problem is with spaces in the filenames. Apparently Automator delimits the list of files with spaces. So I have spaces in the filenames and spaces between the files. So my bash script just sees a list like this:
    /Users/johnt/Documents/3rd Party Audio For Conversion/WFWC - 3.6.2009 3.7.2009/01c Director Report March 6 2009.wav /Users/johnt/Documents/3rd Party Audio For Conversion/WFWC - 3.6.2009 3.7.2009/01b Comm Disc Mar 6 2009.wav
    ...with no way to differentiate each file. Is there a way to tell automator to escape the spaces in the file paths so that my loop doesn't try to run through $@ as:
    /Users/johnt/Documents/3rd
    Party
    Audio
    for
    ... etc etc
    Thanks

    Thanks Neil, that was helpful. I'll play with that AppleScript and see what happens.
    I figured this was better suited in the Automator forum since I'm trying to format the output of what Finder sends before it ever hits the Bash script. My Bash script itself has no problem, so I didn't see any point going over to the UNIX forums.
    You gotta love the ability of OSX to be able to handle all sorts of technologies and integrate them well. Apparently, there's nothing Apple can do to make it's users do the same thing.

  • Questions concerning basic bash scripting

    Good evening,
    at the moment we do bash scripting at university, but I seen to encounter some problems in understanding the functionality of bash. I would be very grateful if you guys could help me out with one or another question.
    First one:
    Task to accomplish: Scripts with three arguments. $1 -> source directory, $2 -> file suffix, $3 -> target directory. Search source directory for all files with suffix $2 and copy them to $3.
    I tried to do it, using pipe and xargs, but I am wondering how to pass the filenames found over the pipe.
    find $source -name "*.$suffix" | xargs cp [MISSING ARGUMENT] $target
    How do I access the data I need to fill in as first argument of cp, or isn't it possible to accomplish the task this way?
    Regards,
    cg

    chaosgeisterchen wrote:find $source -name "*.$suffix" | xargs cp [MISSING ARGUMENT] $target
    Almost, you just need the -t flag to cp which basically reverses the order of SOURCE and TARGET in this instance
    find $source -name "*.$suffix" | xargs cp -t $target
    Also, I suggest you escape the * in your find to prevent bash expanding it. Bash shouldn't expand, find should.
    You might like to also use the -iname (as opposed to -name) predicate to find if you don't care about the case of the source files.
    Last edited by fukawi2 (2008-06-02 03:13:37)

  • Bash script doesn't work (Also, help me condense it)...

    I am trying to make myself a bash script which combines files together based off of a config file. It is automating combining the audio book tracks I ripped of my CDs into chapters for easier reference. My first problem is that even though I used ', cat still thinks that everything is a separate file. My second problem is that it is way too long, any way I can have it automatically go up 1 chapter until a specified number (ie, until the value of the CHAPTERS variable)? Thanks to those who help.
    chapcomb.sh
    #!/bin/bash
    # * ChapterCombine *
    # * By smartboyathome *
    # * A script which was made to combine *
    # * chapters from ripped audio books *
    # * together, but can be edited to *
    # * combine just about anything. *
    # * The config file is located in your *
    # * home directory, under the name *
    # * '.chapcomb.config'. If you do not *
    # * have this file, create it. *
    # * Otherwise this script will not *
    # * run, as it won't have the proper *
    # * variables. *
    # * This can be changed by changing *
    # * the CONFIG variable below. *
    # * Licensed under: *
    # * SmartLicense version 1.0 *
    VERSION=0.1
    usage() {
    echo "Chapter Combine v$VERSION"
    echo "A configuration file must be made in order to use this script. Configuration files are located at $CONFIG. This can be changed by adding CONFIG='blah' before this command, or by changing the script directly. See the sample file for how it should look."
    while [ "$#" -ne "0" ]; do
    case $# in
    --help)
    usage
    exit 0
    -h)
    usage
    exit 0
    esac
    done
    # The config file stuff.
    if [ -z "$CONFIG" ]; then
    CONFIG="$HOME/.chapcomb.config"
    fi
    . $CONFIG
    cd "$BOOKDIR"
    combine() {
    # Checks if file exists, and if so, deletes it.
    if [ -a $NAME ]; then
    rm $NAME
    fi
    # Combines files
    cat $FILES >> $NAME
    # Checks to make sure that the chapter combined ok.
    if [ -s "$NAME" ]; then
    echo "File $NAME is ok."
    else
    echo "File $NAME had an error and didn't combine. Please fix config file and rerun this script."
    exit 0
    fi
    chapter01
    combine
    chapter02
    combine
    chapter03
    combine
    chapter04
    combine
    chapter05
    combine
    chapter06
    combine
    chapter07
    combine
    chapter08
    combine
    chapter09
    combine
    chapter10
    combine
    chapter11
    combine
    chapter12
    combine
    chapter13
    combine
    chapter14
    combine
    chapter15
    combine
    chapter16
    combine
    chapter17
    combine
    chapter18
    combine
    chapter19
    combine
    chapter20
    combine
    chapter21
    combine
    chapter22
    combine
    chapter23
    combine
    chapter24
    combine
    chapter25
    combine
    chapter26
    combine
    chapter27
    combine
    chapter28
    combine
    chapter29
    combine
    .chapcomb.config
    # Config file for ChapterCombine
    # DO NOT DELETE, OR CHAPTERCOMBINE WILL NOT FUNCTION!
    # Book's Directory
    BOOKDIR='/media/Home/aabbott/Star Wars Fate of the Jedi Outcast'
    # Each chapter's settings.
    chapter01() {
    # FILES='Outcast\ Disc\ 1/01\ Track\ 1.mp3 Outcast\ Disc\ 1/02\ Track\ 2.mp3 Outcast\ Disc\ 1/03\ Track\ 3.mp3 Outcast\ Disc\ 1/04\ Track\ 4.mp3'
    FILES="'Outcast Disc 1'/{'01 Track 1','02 Track 2','03 Track 3','04 Track 4'}.mp3"
    NAME='Chapter01.mp3'
    chapter02() {
    # FILES='Outcast\ Disc\ 1/05\ Track\ 5.mp3 Outcast\ Disc\ 1/06\ Track\ 6.mp3 Outcast\ Disc\ 1/07\ Track\ 7.mp3 Outcast\ Disc\ 1/08\ Track\ 8.mp3 Outcast\ Disc\ 1/09\ Track\ 9.mp3 Outcast\ Disc\ 1/10\ Track\ 10.mp3 Outcast\ Disc\ 1/11\ Track\ 11.mp3'
    FILES="'Outcast Disc 1'/{'05 Track 5','06 Track 6','07 Track 7','08 Track 8','09 Track 9','10 Track 10','11 Track 11'}.mp3"
    NAME='Chapter02.mp3'
    chapter03() {
    # FILES='Outcast\ Disc\ 1/12\ Track\ 12.mp3 Outcast\ Disc\ 1/13\ Track\ 13.mp3 Outcast\ Disc\ 1/14\ Track\ 14.mp3 Outcast\ Disc\ 1/15\ Track\ 15.mp3 Outcast\ Disc\ 1/16\ Track\ 16.mp3'
    FILES="'Outcast Disc 1'/{'12 Track 12','13 Track 13','14 Track 14','15 Track 15','16 Track 16'}.mp3"
    NAME='Chapter03.mp3'
    chapter04() {
    # FILES='Outcast\ Disc\ 2/01\ Track\ 1.mp3 Outcast\ Disc\ 2/02\ Track\ 2.mp3 Outcast\ Disc\ 2/03\ Track\ 3.mp3 Outcast\ Disc\ 2/04\ Track\ 4.mp3'
    FILES="'Outcast Disc 2'/{'01 Track 1','02 Track 2','03 Track 3','04 Track 4'}.mp3"
    NAME='Chapter04.mp3'
    chapter05() {
    FILES="'Outcast Disc 2'/{'05 Track 5','06 Track 6','07 Track 7','08 Track 8'}.mp3"
    NAME='Chapter05.mp3'
    chapter06() {
    FILES="'Outcast Disc 2'/{'09 Track 9','10 Track 10','11 Track 11','12 Track 12','13 Track 13'}.mp3"
    NAME='Chapter06.mp3'
    # This one needs some special parameters as the chapter is split between two Discs.
    chapter07() {
    FILES="{'Outcast Disc 2'/{'14 Track 4','15 Track 15','16 Track 16','17 Track 17'}.mp3,'Outcast Disc 3'/{'01 Track 1','02 Track 2','03 Track 3'}}.mp3"
    NAME='Chapter07.mp3'
    chapter08() {
    FILES="'Outcast Disc 3'/{'04 Track 4','05 Track 5','06 Track 6','07 Track 7','08 Track 8'}.mp3"
    NAME='Chapter08.mp3'
    chapter09() {
    FILES="'Outcast Disc 3'/{'09 Track 9','10 Track 10','11 Track 11'}.mp3"
    NAME='Chapter09.mp3'
    chapter10() {
    FILES="'Outcast Disc 3'/{'12 Track 12','13 Track 13','14 Track 14','15 Track 15'}.mp3"
    NAME='Chapter10.mp3'
    chapter11() {
    FILES="'Outcast Disc 4'/{'01 Track 1','02 Track 2','03 Track 3'}.mp3"
    NAME='Chapter11.mp3'
    chapter12() {
    FILES="'Outcast Disc 4'/{'04 Track 4','05 Track 5','06 Track 6','07 Track 7','08 Track 8'}.mp3"
    NAME='Chapter12.mp3'
    chapter13() {
    FILES="'Outcast Disc 4'/{'09 Track 9','10 Track 10','11 Track 11'}.mp3"
    NAME='Chapter13.mp3'
    chapter14() {
    FILES="'Outcast Disc 4'/{'12 Track 12','13 Track 13','14 Track 14'}.mp3"
    NAME='Chapter14.mp3'
    chapter15() {
    FILES="{'Outcast Disc 4'/'15 Track 15','Outcast Disc 5'/{'01 Track 1','02 Track 2','03 Track 3','04 Track 4','05 Track 5'}}.mp3"
    NAME='Chapter15.mp3'
    chapter16() {
    FILES="'Outcast Disc 5'/{'06 Track 6','07 Track 7','08 Track 8','09 Track 9'}.mp3"
    NAME='Chapter16.mp3'
    chapter17() {
    FILES="'Outcast Disc 5'/{'10 Track 10','11 Track 11','12 Track 12','13 Track 13'}.mp3"
    NAME='Chapter17.mp3'
    chapter18() {
    FILES="{'Outcast Disc 5'/'15 Track 15','Outcast Disc 6'/{'01 Track 1','02 Track 2'}}.mp3"
    NAME='Chapter18.mp3'
    chapter19() {
    FILES="'Outcast Disc 6'/{'03 Track 3','04 Track 4','05 Track 5','06 Track 6','07 Track 7','08 Track 8'}.mp3"
    NAME='Chapter19.mp3'
    chapter20() {
    FILES="'Outcast Disc 6'/{'09 Track 9','10 Track 10','11 Track 11','12 Track 12','13 Track 13','14 Track 14'}.mp3"
    NAME='Chapter20.mp3'
    chapter21() {
    FILES="'Outcast Disc 6'/{'15 Track 15','16 Track 16','17 Track 17','18 Track 18','19 Track 19'}.mp3"
    NAME='Chapter21.mp3'
    chapter22() {
    FILES="'Outcast Disc 7'/{'01 Track 1','02 Track 2','03 Track 3','04 Track 4'}.mp3"
    NAME='Chapter22.mp3'
    chapter23() {
    FILES="'Outcast Disc 7'/{'05 Track 5','06 Track 6','07 Track 7','08 Track 8'}.mp3"
    NAME='Chapter23.mp3'
    chapter24() {
    FILES="'Outcast Disc 7'/{'09 Track 9','10 Track 10','11 Track 11','12 Track 12','13 Track 13'}.mp3"
    NAME='Chapter24.mp3'
    chapter25() {
    FILES="{'Outcast Disc 7'/{'14 Track 14','15 Track 15','16 Track 16','17 Track 17'},'Outcast Disk 8'/'01 Track 1'}.mp3"
    NAME='Chapter25.mp3'
    chapter26() {
    FILES="'Outcast Disc 8'/{'02 Track 2','03 Track 3','04 Track 4','05 Track 5'}.mp3"
    NAME='Chapter26.mp3'
    chapter27() {
    FILES="'Outcast Disc 8'/{'06 Track 6','07 Track 7','08 Track 8','09 Track 9'}.mp3"
    NAME='Chapter27.mp3'
    chapter28() {
    FILES="'Outcast Disc 8'/{'10 Track 10','11 Track 11','12 Track 12','13 Track 13'}.mp3"
    NAME='Chapter28.mp3'
    chapter29() {
    FILES="'Outcast Disc 8'/{'14 Track 14','15 Track 15','16 Track 16'}.mp3"
    NAME='Chapter29.mp3'

    kumyco wrote:
    for FILES=test/{a,b,c} you may want to do something like
    FILES=$(echo test/{a,b,c})
    That's a good one. And eval would work with simple examples, but once you have spaces and such in filenames it won't work I think.
    If you are going to do this often, then there are too many things that can go wrong with a script that tries to automatically generate the filenames. Even 01* can go wrong.
    So if you do have the filenames all in the .conf, then you can replace FILES= with cat and NAME= with >
    The actual script doesn't add that much, except checking if it exists (just use > instead of >>) and if it isn't empty (not really necessary) (why did you put a license on that? is that even legal?)
    So just use the .conf file as the main script.
    Turn this:
    BOOKDIR='/media/Home/aabbott/Star Wars Fate of the Jedi Outcast'
    chapter01() {
    FILES="'Outcast Disc 1'/{'01 Track 1','02 Track 2','03 Track 3','04 Track 4'}.mp3"
    NAME='Chapter01.mp3'
    chapter02() {
    FILES="'Outcast Disc 1'/{'05 Track 5','06 Track 6','07 Track 7','08 Track 8','09 Track 9','10 Track 10','11 Track 11'}.mp3"
    NAME='Chapter02.mp3'
    into this:
    cd '/media/Home/aabbott/Star Wars Fate of the Jedi Outcast'
    cat 'Outcast Disc 1'/{'01 Track 1','02 Track 2','03 Track 3','04 Track 4'}.mp3 > 'Chapter01.mp3'
    cat 'Outcast Disc 1'/{'05 Track 5','06 Track 6','07 Track 7','08 Track 8','09 Track 9','10 Track 10','11 Track 11'}.mp3 > 'Chapter02.mp3'
    Right?
    Why would you build anything around that?
    If you are sure the filenames are all the same, you can use *
    cat *\ 1/*\ {1..4}.mp3 > Chapter01.mp3
    cat *\ 100/*\ {70..99}.mp3 > Chapter99.mp3

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

  • Bash script - sqllite insert problem

    So, I'm making a bash script that inserts a config file into a database, but I can't get it to work.
    This is my best attempt so far:
    name="bashrc"
    location="/home/user/.bashrc"
    content=`cat "$location"`
    sqlite3 testdb "insert into dbase values ('`echo $name`','`echo "$location"`','`echo "$content"`')"
    the table is
    create table dbase(name text, location text, data text)
    I had a hard time trying to figure out how I'd be able to get $variables to work (because of the quotes) and this echo style seems to work, but there seems to be no way to insert the config file into the database.
    plaintext files seem to work no problem, but when I'm trying to insert some config file, it spits out errors. (It seems like it's trying to execute the file somehow?)
    Last edited by initbox (2009-08-29 15:28:49)

    initbox wrote:I was thinking the single quotes were stopping bash from replacing $variables with the content, hence the echoes.
    your single quotes are inside a double quote, so to bash they're just another character in the string.
    I'm still getting an SQL syntax error, so bash is no longer getting in the way, but this thing is a true nightmare. What next? This turned out to be way harder than I expected, I'm just doing this as a "fun" learning experiment.
    Your error is probably because I was escaping the quotes for bash, and I should have been escaping them for sqlite. In sqlite, escaping a quote is done by doubling it, so ' is escaped to '' (that's two apostrephes side by side, not a double quote. Compare '' and ").
    This untested sed command might work:
    content = $(cat $location | sed "s/\'/\'\'/g")
    The \'s are escaping the quote from bash, what its really doing is replacing ' with ''.
    Dusty

  • Bash script run via cron not executing MYSQL command

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

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

  • Bash: script not working even after using shopt

    below is script i am trying. I am trying to get the latest modified file in a folder:
    #!/bin/bash
    shopt -s extglob
    name=$(echo *(om[1]))
    echo $name
    i am expecting filename instead *(om[1]) is echoed. As such the script does not give any error due to using shopt.
    i try the command on commandline it gives the filename as output.
    % cd other
    % echo *(om[1])
    mumbai123.txt
    why echo *(om[1]) is working on commandline but not in bash script.
    Last edited by sant527 (2014-10-02 03:53:53)

    sant527 wrote:why echo *(om[1]) is working on commandline but not in bash script.
    Are you using zsh as your shell?

  • Bash script running on my MBP 10.7.4 but not on other Macs (all 10.7.4)

    A friend of mine wrote me this short script to run in terminal that downloads a particular file every n seconds from a password protectected FTP site. The script worked on his linux machine and on my Mac but not on my collegues Macs. I'm wondering if anybody knows reasons why it may be failing on other Macs.
    We changing the first line from: #!/bin/sh to #!/bin/bash
    and exceuting with
    user_prompt_$ bash ./download_stats.sh
    Another idea is to script cyberduck but it doesn't support applescript though may have a comand line interface (looking into that at present).
    There error output from one of the accounts it fails on follows the script listing.
    #!/bin/sh
    # =================================================================
    # Download XML_stats Bash Script
    # Filename:     download_stats.sh
    # Arguments:    input_filename  - file to be downloaded from remote server. Optional.
    #               poll_interval   - seconds delay between downloads. Optional (input_filename must be present)
    # Use:          Invoke from shell, e.g. ./download_stats.sh
    # Author:       Luke Neeson
    # Date Created: 2012-05-31
    # Comments:     This script will download a given file, input_filename, at the given interval, poll_interval.
    # Notes:
    # - .netrc is required in the current directory and must contain the logon details for the fox server. This could be installed in the user home directory, if so, delete the line marked below.
    # =================================================================
    # If the .netrc is in the directory of this script, the following must be enabled. If the user's home .netrc is to be used, comment out the following line:
    export HOME="`pwd`"
    export input_filename="the_file_I_want_as_default.xml"
    export poll_interval=10
    if [ ! -z "$1" ] ; then
      export input_filename="$1"
      if [ ! -z "$2" ] ; then
        export poll_interval="$2"
      fi
    fi
    while [ true ]
    do
      ftp access.foxsports.com.au << EOF 2>&1 | sed 's/.*AUTH GSSAPI.*//g' | sed 's/.*KERBEROS.*//g'
      get  "$input_filename"
      quit
    EOF
      sleep $poll_interval
    done
    ERRORS RETURNED:
    a-mbp:~ macca$
    a-mbp:~ macca$ cd ~/stats/download_rugby_stats/
    a-mbp:download_stats a$ sh download_rugby_stats.sh
    : command not founds.sh: line 16:
    : command not founds.sh: line 19:
    : command not founds.sh: line 22:
    download_stats.sh: line 39: syntax error: unexpected end of file
    a-mbp:download_stats a$
    Those are the blank lines and 39 is the last line of script.

    Thanks Bob, Luke mentioned which but didn't go into it.
    cat -vte download_rugby_stats.sh   ——>    Does this look good to you?
    # ================================================================= $
    # Download Rugby Stats Bash Script$
    #$
    # Filename:     download_rugby_stats.sh$
    # Arguments:    input_filename  - file to be downloaded from remote server. Optional.$
    #               poll_interval   - seconds delay between downloads. Optional (input_filename must be present)$
    # Use:          Invoke from shell, e.g. ./download_rugby_stats.sh$
    # Author:       Luke Neeson$
    # Date Created: 2012-05-31$
    # Comments:     This script will download a given file, input_filename, at the given interval, poll_interval. $
    # Notes: $
    # - .netrc is required in the current directory and must contain the logon details for the fox server. This could be installed in the user home directory, if so, delete the line marked below.$
    # ================================================================= $
    $
    # If the .netrc is in the directory of this script, the following must be enabled. If the user's home .netrc is to be used, comment out the following line:$
    export HOME="`pwd`"$
    $
    export input_filename="Rugby_IRB20120101_Client.xml"$
    export poll_interval=10$
    $
    if [ ! -z "$1" ] ; then$
      export input_filename="$1"$
      if [ ! -z "$2" ] ; then$
        export poll_interval="$2"$
      fi$
    fi$
    $
    while [ true ]$
    do $
      ftp access.foxsports.com.au << EOF 2>&1 | sed 's/.*AUTH GSSAPI.*//g' | sed 's/.*KERBEROS.*//g'$
      get  "$input_filename"$
      quit$
    EOF$
      sleep $poll_interval$
    done$
    $

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

  • How to run gdb from a bash script?

    I'm trying to use gdb for the 1st time.  I'd like to start it up by launching a bash script which will provide a file name for gbd commands and a file name for the executeable.  I've tried every which way but nothing works.  Can someone help?

    With respect to .gdbinit, the following is from the gdb.pdf documentation
    <http://www.gnu.org/software/gdb/documentation/>
    When you start gdb, it automatically executes commands from its init files, normally called ‘.gdbinit’. During startup, gdb does the following:
    1. Reads the init file (if any) in your home directory.
    2. Processes command line options and operands.
    3. Reads the init file (if any) in the current working directory.
    4. Reads command files specified by the ‘-x’ option.
    So you can have a different .gdbinit in the current working directory, which can be different for each program you are writing, assuming you wish to use separate directories for your projects.
    gdb has a 'source filename' command, which you can use to execute commands stored in a file anytime you want.  So you could put your breakpoints in a file that you then exeucte within gdb using
    source file.with.your.breakpoints
    Of course the file could have ANY gdb commands in it, not just breakpoints.
    Did you mean you compile your program with -g as in
    gcc -g program.c -o program
    Or did you mean -ggdb I've always used -g, but reading the gcc man page, I do not see any problems using -ggdb.
    Message was edited by: BobHarris

  • Simple bash scripting help needed..

    I want to learn som simple bash scripting in order to automate various tasks.. Im totally noob, so bear with me
    First of all I would like to set configs without using nano.. is there a simple command for this? For example if i want change my hostname in /etc/rc.conf.. how can i print the current vallue and how can i change it`?
    i was thinking something like this to get the current value:
    # cat /etc/rc.conf | grep HOSTNAME=
    which returns HOSTNAME="myhostname"
    how can i change this value with one or more commands whitout touching the rest of the file?

    abesto wrote:
    A slightly naive solution:
    CHOICE="lisa"
    NAMES="homer marge lisa bart maggie"
    if [ "`echo \" $NAMES \" | grep \" $CHOICE \"`" ]; then
    echo "this is how you do it"
    fi
    The extra spaces inside the escaped quotes are to ensure that only a whole word is "matched".
    You can also replace the elif's with a loop through a list of "the other variables". Then you'd use the loop variable instead of $CHOICE above.
    grep can check on word-bounderies with \< and \>, or with the -w switch. The -q switch suppresses any messages and exits with exit-code 0 when the first match is found:
    if echo "${NAMES}" | grep -qw "${CHOICE}"; then
    Nice and readable, should work, but i haven't tested it
    EDIT:
    Procyon wrote:CHOICE="lisa"
    NAMES="homer marge lisa bart maggie"
    if [[ $NAMES =~ $CHOICE ]]; then echo match; fi
    This one also matches elisa, ie. no check on word bounderies. You should be carefull with that
    Last edited by klixon (2009-04-23 09:40:22)

  • Bash scripts with rox

    in rox-filer you can "send" files to bash scripts by right clicking on them and selecting the script.  for example:
    mogrify -format jpg $1
    i use these scripts all the time and they are really handy but they are limited.
    $1 uses the whole path and filename so it is almost impossible to do simple renaming or copy a file to a server without it being copied to /targetdir/fullpath/filename, for example.
    I am trying to work out how to get the filename into my scripts - with the full path - and then chop it up into path, filename, extention.  i read about word modifiers in bash e.g. !$:h - which works great on the command line but not in scripts - any ideas?

    You mean dirname, basename commands?
    This should be what you are looking for (I hope):
    http://www.splike.com/howtos/bash_faq.html

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

Maybe you are looking for

  • RAID degraded - mirrored striped volumes - how to see if mirroring is working

    I've set up a mirrored raid drive. It keeps showing it as 'degraded', even though I've tested each disk separately and they come up OK. What does it mean in this report by 'rebuilding'? How do I sort out this 'degraded' status? How can I tell if mirr

  • PSE 11 Organiser wont display thumbnails only egg timer icons ?

    I have been using PSE 11 for about 6 months with no problems, however, yesterday the prog froze and I had to switch off and re-boot. Now all new uploads are displayed in the organiser as egg timer icons. These will open, but only one at a time when d

  • Bank stmt issue

    hifriends I have doubht, In FF67, Manual bank stmt display, in that bank stmt some transactions are showing Posting completed ,some transactions are showing posting incompleting, if we double click on posting incomplting status field showing  g/l pos

  • Sub Asset No layout Change

    He Experts, My client req is --  when they  are trying to create sub-asset number for all Asset classes, depn.key, useful life & original depn. start date are not editable. Please advise me how to edit dep key and useful life in sub asset master. Tha

  • How to upload files(particularly pictures) in JSP & Servlet

    Please help me.That is the greatest requirement of my MIT final term. Thank in advance. Edited by: Zahid_Ghafoor on Sep 10, 2008 12:40 AM