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.

Similar Messages

  • Newb bash script

    Well I've had linux for about a year or so now....Well I suppose longer than that but I didn't use it for a while but here I am full time user of Linux for about a year now, wahoo!
    Anyways, I suppose its time to dabble into some coding so I can understand those pesky pkgbuilds when I wanna change them...
    Basically right now I have the linux client Team Fortress 2 dedicated server installed and it has a command to run which starts the script.  I made a script in /usr/bin that I can call on quickly with just 'tf2server' to fire up the server when I want.  It already has the options in that script such as the players and which map to load.
    ./srcds_run -game tf +maxplayers 5 +map
    is basically the line that it calls. What I want to do though is instead of having to go to the folder where it is and running that command with different options when I want to each time I'd like to be able to just do something like...
    tf2server cp_well
    for example, and then it would use well for the map.  I know that in terminal you can type --help on most commands and it will show you usage, so basically my question is....Is there a guide, or someone willing to give an example on how I can accomplish this? I'm assuming it will only take bash and some wildcards of some kind to do.
    Help is appreciated

    SiegeMachine wrote:./srcds_run -game tf +maxplayers 5 +map
    Unless your script is explicitly cd'ing into the directory for 'srcds_run', then attempting to invoke the command found in the current directory is probably not what you want.  If this is the case, I'd either have the script change to the correct directory itself, or ensure the path to srcds_run is in your $PATH and remove the leading "./".  When running a script, the current directory is that which the script was invoked from and not that which the script is located.
    To accept options as in your example is quite simple:
    ./srcds_run -game tf +maxplayers 5 +map $@
    $@ evaluates to the argument(s) specified.  So, assuming the '+map' option takes the name of a map as an argument:
    tf2server cp_well
    Should work fine.  With this you can also specify any additional settings for the server.  E.g.,:
    tf2server cp_well +timelimit 30
    (Note: I know nothing about Team Fortress. '+timelimit' probably doesn't exist; I'm just making things up )
    If you're interested in learning shell scripting, Advanced Bash Scripting (PDF) is an excellent resource.
    Hope this helps.
    Last edited by chpln (2009-12-17 09:54:15)

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

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

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

  • Newbie Action Script Help

    Hello List.
    This is my first try at Flash.
    I tried the drag and drop demo at
    http://monkeyflash.com/tutorials/flash-drag-and-drop/.
    It works well allowing me to drag an item and have it register when
    it is dropped on the correct target.
    I want to modify it so that I can drag an item to multiple
    locations... not just one.
    My desired application is the ability to drag pendents or
    charms onto a bracelet or chain and have them "snap" to the chain.
    With the above demo, I can see how 90% of it would work, but I
    cannot figure out how to have multiple targets named the same. The
    bulk of the code is attached.
    The line I believe needs to changed is this one:
    if (event.target.dropTarget != null &&
    event.target.dropTarget.parent == myTarget){
    I need this part :event.target.dropTarget.parent == myTarget
    to read something to the affect of:
    if item being dropped is over object A OR object B OR object
    C OR object D than ... rest of my code
    Can this be done?
    Any help is greatly appreciated.

    if drag1MC is one of your dragable movieclips and has
    acceptable drop-targets mc1, mc2,mc3:
    drag1MC.droptargetA = [mc1,mc2,mc3];
    function dropIt(event:MouseEvent):void {
    var mc:MovieClip = MovieClip(event.currentTarget);
    mc.stopDrag();
    var success:Boolean = false;
    for(var ind:int=0;ind<mc.droptargetA.length;ind++){
    if(mc.dropTarget!=null&&mc.dropTarget==mc.dropTargetA[ind]){
    success = true;
    mc.x = mc.dropTargetA[ind].x;
    mc.y = mc.dropTargetA[ind].y;
    break;
    if (success){
    reply_txt.text = "Good Job!";
    } else {
    reply_txt.text = "Try Again!";
    }

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

  • SQLPlus output within bash script

    Hey everyone, I wasn't sure if this should go here or in the SQL forum or the Linux forum, but here goes:
    Using Oracle10g on Linux, I'm using a bash script to run an sql script, but when I try to echo the results, it shows the output in a single line.
    Here's the script
    USERLIST=`sqlplus -s  / AS SYSDBA <<EOF
       set head off
       set verify off
       set feedback off
       SELECT username from dba_users;
       exit;
    EOF
    `
    echo $USERLIST;And here's the output:
    oracle@apps scripts]$ ./userl.sh
    PAYROLL HR2 CORE DEMO TIMEKEEPING SYS EXPENSE Is there anyway so that the output can be shown with line breaks, where all the output is not on one line? I understand I can spool to a file using the spool command, however I'd like to try and get it working this way first.
    Any help would be much appreciated, thanks.
    Edited by: oscrub on Sep 22, 2010 6:46 PM

    Handle:      oscrub
    Status Level:      Newbie
    Registered:      Oct 5, 2008
    Total Posts:      7
    Total Questions:      4 (3 unresolved)
    so many questions & so few answers.
    sh  t.sh
    SYSTEM
    SYS
    MGMT_VIEW
    DBSNMP
    SYSMAN
    USER1
    DBADMIN
    HR
    OE
    SH
    BONGO
    SCOTT
    OUTLN
    OLAPSYS
    SI_INFORMTN_SCHEMA
    OWBSYS
    ORDPLUGINS
    XDB
    ANONYMOUS
    CTXSYS
    ORDDATA
    OWBSYS_AUDIT
    APEX_030200
    APPQOSSYS
    WMSYS
    EXFSYS
    ORDSYS
    MDSYS
    FLOWS_FILES
    SPATIAL_WFS_ADMIN_USR
    SPATIAL_CSW_ADMIN_USR
    APEX_PUBLIC_USER
    DIP
    IX
    MDDATA
    PM
    BI
    XS$NULL
    ORACLE_OCMHow do you spell S-Q-L?

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

Maybe you are looking for

  • Two libraries on one drive, music co-mingled, want to separate:

    Here is my situation: I have two libraries, lets call one Lossy, and the other Lossless. The Lossy library is ~140GB of 192-364kbps AAC files and a few mp3's. I use this library to sync all the family iPods and it also has all our ripped and download

  • Formatting a date that is inserted into a text object

    The on-line documentation for inserting a date into a form letter instructs a user to insert a Print Date into a text object.  To format the date, the user is instructed to double-click on the date object and then right click and select Format {Print

  • Missing text, not all, in some .pdf files

    I have just started to receive some .pdf files with photos on them and text. But there are places where there should be text and it does not show up when I receive. Others are able to view this particular .pdf I'm citing in its entirety. The person w

  • Need help in this design, SHAPES!

    Hello everyone. I have a simple programming project but I'm getting caught up on what should be the super class. Its shapes. I have the following: A Quadrilateral, Trapezoid, Parallelogram, Rectangle and Square. At first I had it designed like Quadri

  • I'm unable to drag-and-drop a script from the Story window in Premiere Pro to a clip

    I have a film script visible in the Story window, and I try to drag it to the relevant clip in the Premiere Pro project window-but nothing happens. I have also tried to attach an astx file, but I get the "matching scene number not found" error, even