Bash script help?

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

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

Similar Messages

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

  • Newbie bash scripting help!

    Hello,
    I would like some help with a simple script.
    I have say 10 text files (***.txt) in a directory.  I want to make each *** into a subdirectory, insert the respective ***.txt file into that subdirectory as well as insert three other files into each subdirectory.
    I then want to create a loop that will run a seperate script, which I already have, on each folder.
    Thanks for any help

    DonVla wrote:
    jnwebb wrote:
    Hello,
    I would like some help with a simple script.
    I have say 10 text files (***.txt) in a directory.  I want to make each *** into a subdirectory, insert the respective ***.txt file into that subdirectory as well as insert three other files into each subdirectory.
    I then want to create a loop that will run a seperate script, which I already have, on each folder.
    Thanks for any help
    i think you need some basics:
    http://www.gnu.org/software/bash/manual/bashref.html
    http://wooledge.org:8000/BashGuide
    http://wooledge.org:8000/BashFAQ
    http://wooledge.org:8000/BashPitfalls
    http://sed.sourceforge.net/sed1line.txt
    http://student.northpark.edu/pemente/awk/awk1line.txt
    Sorry for always being so propagandish, but I feel it's worthwile for your enjoyment and efficiency to mention that perl does all this and more. http://perldoc.perl.org
    But, uh, "use the right tool for the right job". For the last 3 characters problem, briest gives the right solution. It works for me. Make sure you put the '-' in front of the 3.

  • A little bash scripting help..

    Hello, this is a script I made in /etc/rc.d/sd to mount my SD card as my home partition in my eee pc.
    Here's the script:
    http://pastebin.ca/1807492
    The script works, but I keep getting this error.
    [root@UpEarly coda]# /etc/rc.d/sd start
    :: Mounting SD card... [BUSY] Waiting for SD card to exist...
    Card exists!
    /etc/rc.d/sd: line 20: [: too many arguments
    Mounted at /home/coda
    [DONE]
    What's wrong with the if statement at line 20?
    Last edited by DeeCodeUh (2010-02-24 00:00:54)

    perbh wrote:Other than that - I've always had problems with
    if test .... and if [ ... ], so these days if I just want to check if true or false I use '&&' or '||'.
    If I want to handle both cases, I do 'if test $? -eq 0; then ...; else ...; fi'
    Maybe this will help ... "test" and "[ ]" are synonymous really.
    test
    Evaluate a conditional expression expr. Each operator and operand must be a separate argument.
    When the [ form is used, the last argument to the command must be a ].
    In other words... you only use test or [] in your "if" statement if your comparing one thing to another, and that will "evaluate" as being either true or false... BUT if your just checking to see if blah blah blah is true... then it's not necc to use those "test" or "[ ]".
    Regarding this if statement:
    if cat /proc/mounts | grep -q $MNTPNT;
    Easiest way for me to remember when to use this is if you just run the command on the command line without the "if" and it returns "something", that means it is "true", if it runs and you get nothing back.. it's returning as "false".
    Example: you can't very well compare/run "x = b" on the command line and have it return anything...so it has to be "evaluated"...that's where "test" or "[ ]" come into play.
    But using "test" or "[ ]" to check if x does equal b, and if x does equal b it does returns true, and if x doesn't equal b it returns false.
    Anyway...that's how I remember it
    Last edited by crouse (2010-02-24 04:58:03)

  • Bash scripting help!!

    Ok, so how do you do something that will save a inputed value, ie:
    Please enter the directory:
    User enters directory and the directory is saved in the script itself.
    echo -n "Please enter the directory: "
    read VAR
    Now I want the var saved inside the script. Then the script will have a if else thing that will check that the directory exists. Do you get what I am saying?

    Come to think of it, I'm actually wrong in saying that a script can't update itself -- it's only a text file after all...
    Here's a rudimentary version of something like this:
    #!/bin/sh
    DEFAULTDIR="/home/user/tmp"
    SCRIPT="/home/filip/scripts/test.sh"
    echo -n "Please enter the directory: "
    read NEWDIR
    sed -i "s#$DEFAULTDIR#$NEWDIR#g" $SCRIPT && echo "Directory Updated" || echo "Update failed"
    EDIT:
    @smoon -- yeah, I don't know why I thought it was impossible...
    Last edited by fwojciec (2008-08-24 20:08:18)

  • 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

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

  • Helpful Linux Bash Scripts for I.T. Admins

    I was wondering if you guys had any recommendations for helpful / simple Bash scripts that do helpful tasks in regards to Linux system administration? I have never created or used a Bash shell script but know that many of you guys do. I have no programming experience what so ever so decided to ask if you guys do have one or few scripts that are useful in basic administration tasks, could you please post them or at least point someone who is interested in the right direction?
    Thank you so much!

    I'm no sysadmin but one were to use command-line a lot i would give ZSH a shot. A nicely configured zsh shell can be unbelievably comfortable and is certainly a great tool.
    As for scripts I always thought of them as little helpers customized for certain situations. For instance easing repetitive tasks, batching some steps and timing/automating little things. For general purpose I'd probably look at available software first.
    Maybe tmux for terminal management, ranger for file management, a tiling window manager for efficiency, ssh and other survaillance/maintenance software? Personally, I'd very much like to hear, too, what software/scripts/.. linux systems admins use to keep the work to a minimum .

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

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

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

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

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

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

  • Using Bash script to edit config file

    This is a really simple question, but given that I'm just learning Bash scripting and having this solved now would be really illustrative for me, I would really thank some help here.
    I'm using uzbl, and running Tor+Polipo. So, as you will see below in the tail of the config file, there is a line to redirect the requests of uzbl through Polipo.
    # === Post-load misc commands ================================================
    sync_spawn_exec @scripts_dir/load_cookies.sh
    sync_spawn_exec @scripts_dir/load_cookies.sh @data_home/uzbl/session-cookies.txt
    # Set the "home" page.
    #set uri = https://duckduckgo.com
    # Local polipo proxy
    set proxy_url = http://127.0.0.1:8123
    # vim: set fdm=syntax:
    What I want to accomplish is to comment in/out that line with a key shortcut on Awesome. I've thought of doing 2 scripts to do so and using 2 differente key shortcuts, but I want to "toggle" the proxy redirection with only 1 shortcut. To do so, I suppose that the script should go something like:
    if
    tool 'set proxy_url = http://127.0.0.1:8123' config_file
    then
    tool '#set proxy_url = http://127.0.0.1:8123' config_file
    else
    if
    tool '#set proxy_url = http://127.0.0.1:8123' config_file
    then
    tool 'set proxy_url = http://127.0.0.1:8123' config_file
    fi
    fi
    I know little about sed, but I think is the tool for this job. The most intriging part to me is to ask sed to print the regular expression when it finds it in the config file, and use that as an input in the conditional statement.
    Well, this is a mess I have done here. Hope there is a simple answer to this.
    Thanks in advance.-

    You can do this with a single sed command:
    sed -i 's/^#set proxy_url/set proxy_url/;
    t end;
    s/^set proxy_url/#set proxy_url/;
    : end' config_file
    This edits the file in-place (-i) and first tries to replace the commented with the uncommented line. If that suceeds, sed jumps to the "end" label. If not, it tries to replace the uncommented with the commented line. Thus you don't have to include any logic about the current state: if the first substitution succeeds, the line was obviously commented, if not, it was uncommented, and the second substitution should succeed.
    Note that my knowledge of sed is very limited. There might be a simpler way to do this.
    EDIT: For the sake of example, here's how to do the same in bash using regular expressions. Note how this script needs to use a temporary file to simulate in-place editing, how it needs to process the file line by line manually, etc. All things that sed does out of the box...
    #!/bin/bash
    tmp=test.conf.tmp
    echo -n "" > "$tmp"
    while read line; do
    if [[ "$line" =~ ^#set\ proxy ]]; then
    echo "${line/\#/}" >> "$tmp"
    elif [[ "$line" =~ ^set\ proxy ]]; then
    echo "#$line" >> "$tmp"
    else
    echo "$line" >> "$tmp"
    fi
    done < test.conf
    mv test.conf.tmp test.conf
    To answer your original question, the line
    if [[ "$line" =~ ^#set\ proxy ]]; then
    reads: if the line begins with a "#", followed by "set proxy", then...
    Last edited by hbekel (2011-03-20 10:40:16)

  • HOW DO I  RUN A UNIX BASH SCRIPT FROM JAVA??

    HI. Here's a tricky little problem i have. There's a unix bash script that has some commands in it, that manipulate a file. It appends a certain string variable to a file called users. The users file is an ordinary text file.
    I know this script to work perfectly, when i invoke it like this directyl from the command line: ./addusers.sh
    or even: bash /downloads/selinux/policy/addusers.sh
    Now, i have a java program, and its meant to just execute that script. It doesnt throw any Exceptions at runtime. But when i look at the users file, and expect it to have an extra line that was the string variable, the file is UNTOUCHED!
    Again, direct command line invocation works, but not from java. Here's what my invocation from java looks like:
    Process p = Runtime.getRunTime().exec("bash downloads/selinux/policy/addusers.sh");
    The strange thing is, i tried a different bash command. I tried:
    Process p = Runtime.getRunTime().exec("mkdir /temporary");
    and this worked!
    so why not the other one??
    I cant figure it out.

    You say:
    bash /downloads/selinux/policy/addusers.sh
    And you say in Java:
    Process p = Runtime.getRunTime().exec("bash
    downloads/selinux/policy/addusers.sh");
    As if a leading / would be missing from the Java
    version...nyix says:>
    ...OK sorry about that. i DO have a / in front of the downloads.... section in the java method. So its:
    Process p = Runtime.getRunTime().
    exec("bash /downloads/selinux/policy/addusers.sh");
    HELP please?

  • How do I save a "bash" script? (in attempt to fix one of my other problems)

    Here is my original problem:
    http://discussions.apple.com/thread.jspa?threadID=2195627&tstart=0
    I came across this that sounds like it will help my issue:
    http://www.macosxhints.com/article.php?story=20090316190817357
    However, what am I supposed to do with that code? Put it in the Terminal? Save it as an Apple Script? I also got the "lingon" program set up, all I need to do is figure how how to save this "bash" script and all set!
    Any ideas?
    -Scott

    This link might help as it shows how to create the plist using lingon:
    http://mymacfixes.blogspot.com/2009/06/how-do-i-stop-clicking-noise-from-hard.ht ml

  • Conky with a bash script

    I am trying to change the color of my CPU temp text in conky to green, yellow or red based on the CPU temp.  I am getting this in my conky:
    Temperature:  color green33
    Here is my conky line:
    ${voffset 1}${goto 40}Temperature: ${font Droid Sans:style=Bold:size=8}${execpi 120 sensors | grep Core0 | paste -s | cut -c15-18 | xargs ~/.conky/colorize.sh}${hwmon 0 temp 1}°C${color}${font}${alignr}
    Here is my bash script:
    #!/bin/bash
    # colorize.sh
    COOL=65
    WARM=80
    if [[ $1 < $COOL ]];
    then
    echo "color green"
    elif [[ $1 > $WARM ]];
    then
    echo "color red"
    else
    echo "color yellow"
    fi
    exit 0
    Any help would be greatly appreciated.
    Thanks

    Using exec(p)(i) makes your conky run heavier, so, why wouldn't you use the built-in conky variables to achieve the same...
    I'm using: (before "TEXT")
    template2 ${color2}${if_match ${hwmon \1 temp \2}>75}${color orange}${if_match ${hwmon \1 temp \2}>90}${color red}${endif}${endif}${hwmon \1 temp \2}${color1}
    and i call them like: (after "TEXT")
    Temp ${template2 0 1}/${template2 1 1}/${template2 2 2}/${template2 2 4}
    Of course you need to find out what numbers you need to pass to hwmon...

  • Problem with "date -d" function in bash script. Leopard bug?

    I have this really nice rsync bash script that I use to make rotating snapshot backups of my different Ubuntu servers to a single backup server.
    I am now trying to use this same script on my Leopard machine, but it seems to have a serious problem with the following lines of code:
    lday=`date +'image-%Y-%m-%d-%H' -d '1 day ago'`
    lweek=`date +'image-%Y-%m-%d-%H' -d '1 week ago'`
    It generates the following error:
    date: illegal time format
    usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
    [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
    It's clear that it doesn't like the "-d '1 day ago'" part in my code.
    Is there a different way in Leopard to get yesterday's or last week's date in a bash script? Or is this a Leopard bug?
    Could someone please help me out? I've be trying to research this for the past 8 hours, but can't seem to find any solution to this problem.
    Thanks in advance.

    Is there a different way in Leopard to get yesterday's or last week's date in a bash script?
    date -v-1d
    date -v-7d

Maybe you are looking for

  • Photoshop CS5 problem- won't open

    None of my adobe products will open with the exception of Lightroom- please help

  • Packed Material Details Report

    Hi, At the time of delivery we packed the material . and also at the time of delivery i have to give packed details with material and quantity wise is it possible? and also one moth or 2 months etc..,  can i get the packed details which is already de

  • Mac apple access via Citrix AG

    I am attempting to connect my apple Mac mini (late 2012) running Mavericks 10.9.1 on my home wifi via my Citrix AG connection to remote my desktop in my office. My IT guys tell me that once logged in to the portal page and load the Citrix AG client t

  • Sign-In Seal Problems - Mac OSX 10.x

    Hello, Have been using Yahoo Mail from my MacBook and my wife's Windows PC for years. This morning, our sign-in seals disappeared from both computers. I got in touch with the BT Hotline folks and a technician confirmed "a new interface" had just been

  • Just contacted Chat

    Was advised to go to the support portal which of course does not help me at all. I think Adobe has evolved to a company that does not take anymore responsiblities for it products and when they produce new software they take out randomly software that