a truly accidental script
Results 1 to 6 of 6

Thread: a truly accidental script

  1. #1
    Join Date
    Nov 2000
    Location
    buenos aires
    Posts
    335

    a truly accidental script

    i`m testing and trying different things with shell scripts, mostly because i really don`t know anything of it.
    yesterday i was trying some while loops, performing some huge additions; but i guess that i did something very bizarre almost stupid; because all of a sudden, the free space of my hd started to shrinck.
    here is a screen dump of the script:

    #!/bin/bash

    COUNTER=200000
    until [ $COUNTER -lt 100000 ]; do
    echo -----------------------------> $COUNTER
    let COUNTER-=1
    done
    [Thu Feb 1][23:19:25][root@sicanderbul][/var/tmp:]

    >>setterm -dump

    to all of you it must be obvious, but this `thing` created a lot of very small files with nothing but `--------` on it.
    looking at that right now, i understand why that hapenned,ut what i don`t understand is why the files find their way to 2 diferent directories, /etc/rc.d and /var/tmp directories, why is that?

  2. #2
    Join Date
    Feb 2000
    Posts
    10
    When you do:
    echo --------> $COUNTER
    you're redirecting the exit of the echo program to the file $COUNTER instead of putting the string on the screen (as I suppose you wanted to do, just take it out). Each time $COUNTER changes you create a new file. About the way it goes to these directories I'm not very sure 'bout it and seems to be very strange since you don't change your path during execution.

  3. #3
    Join Date
    Nov 2000
    Location
    buenos aires
    Posts
    335
    thanks elric, yes, i was trying to echo to the screen that `------>`.
    looking from a distance, it really looks stupid and obvious.
    i guess the files did `find their way` into those directories because i was executing the program while *in* those directories.
    thank you very much.

  4. #4
    Join Date
    Sep 2000
    Location
    Hallsville, TX
    Posts
    17
    You could just change $COUNTER to /dev/null, and it wouldn't be a problem.

  5. #5
    Join Date
    Mar 2000
    Location
    Elyria, Ohio - USA
    Posts
    2,075
    Just a note. When you are going to echo a combination of multiple words and variables, enclost them in double quotes. As in:

    echo "-----------------------------> $COUNTER"

    The problem was that it took the '----' as being test, the '>' as being the redirector and the contents of $COUNTER as being the file name. If you wanted to log this info to a log file, you can add:

    FILENAME="filename"
    date > $FILENAME
    COUNTER=200000
    until [ $COUNTER -lt 100000 ]; do
    echo "-----------------------------> $COUNTER" >> $FILENAME
    let COUNTER-=1
    done

    If you would like to both view in real time and also save to a file you can do:

    echo "-----------------------------> $COUNTER" | tee $FILENAME

    The tee command will make a copy of the text to $FILENAME and output another to stdout. -mk

    ------------------
    If it ain't broke, fix it till it is.
    If it ain't broke,
    Fix it till it is.

  6. #6
    Join Date
    Nov 2000
    Location
    buenos aires
    Posts
    335
    thanks a lot, every body, i was just trying to learn a bit of scripting. as i said, every time i see `that` i see that is totally obvious what it might produce.
    mike, thank you very much, i`ll try that script tonight.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •