User Controls

Some advanced bash scripting.

  1. #1
    Sophie Pedophile Tech Support
    Alright so while i have the chance i wanted to ask a couple of bash related questions.

    I want to make a script that takes in a list of URLs stores each line as a variable and then passes that variable as an argument to curl, then i want curl to do some magic retrieve some data and print the data to STDOUT. I want this to continue until all the lines in the textfile have been tested in such a manner. Now i want bash to know that it needs to stop after all the lines have been tested so i was thinking i would have to programatically insert some type of End Of File marker to check for.

    I want this all to happen when a function gets called. Now IDK a lot of Bash so i do not even know how i can have it read in a liat like that. Also with regards to functions in Bash is there some special kind of syntax i need to take into account or can i just do this:


    function foo()
    do bar
    return bas


    also in case i want to redirect output to a textfile can i just do:


    myscript.sh >> /tmp/outfile.txt


    Bare in mind my script will prpbably come with args so does bash know i mean redirect when i enter two greater than symbols or will it think i am trying to pass an argument?

    thanks goys
  2. #2
    Is PHP not plausible? Or are you trying to keep it CMD-line?
  3. #3
    Sophie Pedophile Tech Support
    Is PHP not plausible? Or are you trying to keep it CMD-line?

    Not sure honestly, but i wasn't planning on making the tool web based. I could probably do it in C but i don't know any C. And while i do know a bit of python half of the purpose of making the script was teaching myself more bash.
  4. #4
    Merlin Houston
    You will hate yourself if you use bash, just a warning.

    I'd do it like this:
    Read in the entire file to a variable (assuming it's not too large), then split by newline - saving each line to a dynamically created variable or hash list or regular list. You'll know you have reached the end when there are no more newlines. Then use system calls for the curl stuff, manipulate it etc.

    Also you can call php from the command line, hell I think you can even call it like "./myPhpScript", same with javascript. You can write php and js scripts without intending on using it for the web.
  5. #5
    Merlin Houston
    Oh yeah it should redirect fine, the only problem I can see is if you needed ">" to be the parameter itself.
  6. #6
    Lanny Bird of Courage
    This seems like a perfectly suitable job for bash to me, you don't even really need a script or anything, xargs will do this for you:

    lanny@niggasin:~$ cat urls.txt
    http://textfiles.com/art/afinger.txt
    http://textfiles.com/art/bobface.txt
    lanny@niggasin:~$ cat urls.txt | xargs -L 1 curl

    /"\
    |\./|
    | |
    | |
    |>~<|
    | |
    /'\| |/'\..
    /~\| | | | \
    | =[@]= | | \
    | | | | | \
    | ~ ~ ~ ~ |` )
    | /
    \ /
    \ /
    \ _____ /
    |--//''`\--|
    | (( +==)) |
    |--\_|_//--|THE FACE OF "BOB" fnord

    $$$$$$$$$$$$$$$$$$$$$$
    $$$$$$$$$$$$$$$$$$$$$$$$$$$$
    $$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$
    $$$$$$$$$$$$$$ $$$$$$$ $$ $ $$$$
    $$$$$$$$$$$ $$ $$$ $$ $ $ $$$$
    $$$$%$$$ $ $ $$ $$$ $ $ $$ $ $$
    $$$$%%$$$ $ $ $$ $$$ $ $$ $ $ $$$
    $$$$$%%$$$$ $ $ $ $$ $ $$$ $ $$ $$$$
    $$$$$%%%$$$$$ $$$$ $ $ $$ $ $$$$$ $$ $$$$$
    $$$$$$%%%$$$$$$$$$$$ $$ $ $$$$ $ $$$$$$$$$$$$$$$$
    $$$$$$%%%$$$$$$$$$$$$$$$ $$$$$$ $$$$$$$$$$$$$$$$$$$
    $$$$$$%%%$$%%%%%%$$$$$$$$$$$$$$$ $$$$$$$$$ $$$$$$$$
    $$$$$$%%$$%%%%%%%%%$$$$$$$$$$$$$ $$$$$$$ $$$$%$$$
    $$$$$$%$$%%%%%%%%%%%$$$$$$$$$$$$$$$$$ $$$$%%$$$
    $$$$$$$$%%%%%%%%%%%%%$$$$$$$$$$$ $$$$%%$$$
    $$$$$$$%%% $$$$$$$$ $$$%%$$$
    $$$$$$%%% $$$%%$$
    $$$$$$%%% $$$%%$$
    $$$$$%%%% % $$$%%$$
    $$$$$%%%% % $$%%$$
    $$$$$%%%% % $$%%$$
    $$$$$%%%% %% $$$%$$
    $$$$$%%%% %%% $$$%$$
    $$$$$%%%% %% $$$%$$
    $$$$$%%%% %% $$$%$$
    $$$$$%%%% %% $$$%$$
    $$$$%%%% $$$$ %% $$$$%$$
    $ $$$%%%% $$$$$$$$$ $$$$$$$$$%% $$$$$$$
    $$$ $$%%% $$$$$$$$$$ $$$$$$$$$$$%% $$$$$$
    $$$$ %%% $$$ $$$$ $$%% $$$$$$
    $$$$$$%%% $$$$$ $$$$ $$$$$$$$$$ $%% $$$$$$
    $$$$ %%% $$$ $$$$$ $$$$$$ $$$ %%% $$$$$
    $$$$ $$$$$$$$$ $$$$ $$$$$$$$$$$$$$ % $$$$$
    $$$$ $$$ $ $$ $$$$ $$$$$$ $ $ $$ $$$$
    $$$$ $ $$$ %%%$$$ %% $$$ $$$$
    $$$$ %%%% $$ %%%%%% %%% $$$$
    $$$$ %%% %%%%% $ %%%%%%% $$$$
    $$$$ %%%%% $$ %%% $$ $
    $$ $ %% $ $ $$
    $ $$ $ $ $
    $ $$ $ %$ $$ $
    $ $ $ %%$ $$$$
    $$$ $$ $ %%% $ $ $$
    $$ $$ $ %%%% $ $$$ $$ $
    $ $$$ $$ %%%% $$$ $$$ $$$ $
    $ $$$ $$ %%%$$$ $$$$ $$$$ $$$$ $
    $$$$$$$$$$ $$$$$$$$$$$$$$ $$$$$$$$$ $
    $$$$$$$ $$$$$$$$$$$$$$ $$$$$$$$ $
    $$$$$$ %%$$$$$$$$$$$$$$ $$$$$$$$$$$$$$
    $$$ $$ %$$$$$$$$$$ $$$$$$$$$ $$$$
    $$ $ $$$$ $$$$$$$$ $$ $$$
    $$ $ %$$$$ $$ $$$$
    $ $ %%%%$$$ $$$$$$$$$$$$$ $$$
    $$ $$ %%%% $$ $$$$
    $$ $$ %%$$$$ $$$$$$$$$$ $$$
    $ $ $$$$$%%%%%%%%%% $$$$
    $$ $$ $$$$$%%% $$$
    $ $ $$$$ %%%%%%%%%%%%%% $$$
    $$ $$$$ %%%%%%%%%%%%% $$$
    $$$ $ $$$$ $%%%% $$$
    $$ $$ $$$$$ $$$$ $$$
    $ $$ $$ $$$$$$ $$$ $$$
    $ $$$$ $$ $$$$$$ $$$$ $$$
    $ $$$ $$$ $$$$$$ $$$$$$$ $$$
    $ $$$$$$$$$$ $$$$$$ $$$
    $ $$ $$$$$$$$ $$$$$$$$$$$$$$$ $$$
    $$$$$ $$$$$$$ $$$$$$$$$$$$$$$$$$
    $$$$$$ $$$$$ $$$$$$
    $$$$$ $$$$
    $$$$$$ $$$
    $$$$$ $$$
    $$$$$$$$
    $$$$$$


    and


    THE FACE OF "BOB" (SMALL VERSION) 12-13-90

    @@@@@@@^^~~~~~~~~~~~~~~~~~~~~^@@@@@@@@@
    @@@@@@^ ~^ @ @@ @ @ @ I ~^@@@@@@
    @@@@@ ~ ~~ ~I @@@@@
    @@@@' ' _,w@< @@@@
    @@@@ @@@@@@@@w___,w@@@@@@@@ @ @@@
    @@@@ @@@@@@@@@@@@@@@@@@@@@@ I @@@
    @@@@ @@@@@@@@@@@@@@@@@@@@*@[ i @@@
    @@@@ @@@@@@@@@@@@@@@@@@@@[][ | ]@@@
    @@@@ ~_,,_ ~@@@@@@@~ ____~ @ @@@
    @@@@ _~ , , `@@@~ _ _`@ ]L J@@@
    @@@@ , @@w@ww+ @@@ww``,,@w@ ][ @@@@
    @@@@, @@@@www@@@ @@@@@@@ww@@@@@[ @@@@
    @@@@@_|| @@@@@@P' @@P@@@@@@@@@@@[|c@@@@
    @@@@@@w| '@@P~ P]@@@-~, ~Y@@^'],@@@@@@
    @@@@@@@[ _ _J@@Tk ]]@@@@@@
    @@@@@@@@,@ @@, c,,,,,,,y ,w@@[ ,@@@@@@@
    @@@@@@@@@ i @w ====--_@@@@@ @@@@@@@@
    @@@@@@@@@@`,P~ _ ~^^^^Y@@@@@ @@@@@@@@@
    @@@@^^=^@@^ ^' ,ww,w@@@@@ _@@@@@@@@@@
    @@@_xJ~ ~ , @@@@@@@P~_@@@@@@@@@@@@
    @@ @, ,@@@,_____ _,J@@@@@@@@@@@@@
    @@L `' ,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    The holy visage of "Bob" Dobbs is copyright 1990, and probably other
    years as well - MAYBE EVEN YEARS YOU WON'T FIND IN YOUR PINK CALENDAR!
    - by the Church of the SubGenius. Fnord.

    (Note that the face of J.R. ``Bob'' Dobbs is a registered trademark of
    the Church of the SubGenius. Fnord.)

    lanny@niggasin:~$


    Bare in mind my script will prpbably come with args so does bash know i mean redirect when i enter two greater than symbols or will it think i am trying to pass an argument?

    The former, ">>" as well as other bash reserved symbols are never read as arguments. If you want to pass >> as an argument you need to wrap it in quotes.
  7. #7
    Sophie Pedophile Tech Support
    This seems like a perfectly suitable job for bash to me, you don't even really need a script or anything, xargs will do this for you:

    lanny@niggasin:~$ cat urls.txt
    http://textfiles.com/art/afinger.txt
    http://textfiles.com/art/bobface.txt
    lanny@niggasin:~$ cat urls.txt | xargs -L 1 curl

    /"\
    |\./|
    | |
    | |
    |>~<|
    | |
    /'\| |/'\..
    /~\| | | | \
    | =[@]= | | \
    | | | | | \
    | ~ ~ ~ ~ |` )
    | /
    \ /
    \ /
    \ _____ /
    |--//''`\--|
    | (( +==)) |
    |--\_|_//--|THE FACE OF "BOB" fnord

    $$$$$$$$$$$$$$$$$$$$$$
    $$$$$$$$$$$$$$$$$$$$$$$$$$$$
    $$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$
    $$$$$$$$$$$$$$ $$$$$$$ $$ $ $$$$
    $$$$$$$$$$$ $$ $$$ $$ $ $ $$$$
    $$$$%$$$ $ $ $$ $$$ $ $ $$ $ $$
    $$$$%%$$$ $ $ $$ $$$ $ $$ $ $ $$$
    $$$$$%%$$$$ $ $ $ $$ $ $$$ $ $$ $$$$
    $$$$$%%%$$$$$ $$$$ $ $ $$ $ $$$$$ $$ $$$$$
    $$$$$$%%%$$$$$$$$$$$ $$ $ $$$$ $ $$$$$$$$$$$$$$$$
    $$$$$$%%%$$$$$$$$$$$$$$$ $$$$$$ $$$$$$$$$$$$$$$$$$$
    $$$$$$%%%$$%%%%%%$$$$$$$$$$$$$$$ $$$$$$$$$ $$$$$$$$
    $$$$$$%%$$%%%%%%%%%$$$$$$$$$$$$$ $$$$$$$ $$$$%$$$
    $$$$$$%$$%%%%%%%%%%%$$$$$$$$$$$$$$$$$ $$$$%%$$$
    $$$$$$$$%%%%%%%%%%%%%$$$$$$$$$$$ $$$$%%$$$
    $$$$$$$%%% $$$$$$$$ $$$%%$$$
    $$$$$$%%% $$$%%$$
    $$$$$$%%% $$$%%$$
    $$$$$%%%% % $$$%%$$
    $$$$$%%%% % $$%%$$
    $$$$$%%%% % $$%%$$
    $$$$$%%%% %% $$$%$$
    $$$$$%%%% %%% $$$%$$
    $$$$$%%%% %% $$$%$$
    $$$$$%%%% %% $$$%$$
    $$$$$%%%% %% $$$%$$
    $$$$%%%% $$$$ %% $$$$%$$
    $ $$$%%%% $$$$$$$$$ $$$$$$$$$%% $$$$$$$
    $$$ $$%%% $$$$$$$$$$ $$$$$$$$$$$%% $$$$$$
    $$$$ %%% $$$ $$$$ $$%% $$$$$$
    $$$$$$%%% $$$$$ $$$$ $$$$$$$$$$ $%% $$$$$$
    $$$$ %%% $$$ $$$$$ $$$$$$ $$$ %%% $$$$$
    $$$$ $$$$$$$$$ $$$$ $$$$$$$$$$$$$$ % $$$$$
    $$$$ $$$ $ $$ $$$$ $$$$$$ $ $ $$ $$$$
    $$$$ $ $$$ %%%$$$ %% $$$ $$$$
    $$$$ %%%% $$ %%%%%% %%% $$$$
    $$$$ %%% %%%%% $ %%%%%%% $$$$
    $$$$ %%%%% $$ %%% $$ $
    $$ $ %% $ $ $$
    $ $$ $ $ $
    $ $$ $ %$ $$ $
    $ $ $ %%$ $$$$
    $$$ $$ $ %%% $ $ $$
    $$ $$ $ %%%% $ $$$ $$ $
    $ $$$ $$ %%%% $$$ $$$ $$$ $
    $ $$$ $$ %%%$$$ $$$$ $$$$ $$$$ $
    $$$$$$$$$$ $$$$$$$$$$$$$$ $$$$$$$$$ $
    $$$$$$$ $$$$$$$$$$$$$$ $$$$$$$$ $
    $$$$$$ %%$$$$$$$$$$$$$$ $$$$$$$$$$$$$$
    $$$ $$ %$$$$$$$$$$ $$$$$$$$$ $$$$
    $$ $ $$$$ $$$$$$$$ $$ $$$
    $$ $ %$$$$ $$ $$$$
    $ $ %%%%$$$ $$$$$$$$$$$$$ $$$
    $$ $$ %%%% $$ $$$$
    $$ $$ %%$$$$ $$$$$$$$$$ $$$
    $ $ $$$$$%%%%%%%%%% $$$$
    $$ $$ $$$$$%%% $$$
    $ $ $$$$ %%%%%%%%%%%%%% $$$
    $$ $$$$ %%%%%%%%%%%%% $$$
    $$$ $ $$$$ $%%%% $$$
    $$ $$ $$$$$ $$$$ $$$
    $ $$ $$ $$$$$$ $$$ $$$
    $ $$$$ $$ $$$$$$ $$$$ $$$
    $ $$$ $$$ $$$$$$ $$$$$$$ $$$
    $ $$$$$$$$$$ $$$$$$ $$$
    $ $$ $$$$$$$$ $$$$$$$$$$$$$$$ $$$
    $$$$$ $$$$$$$ $$$$$$$$$$$$$$$$$$
    $$$$$$ $$$$$ $$$$$$
    $$$$$ $$$$
    $$$$$$ $$$
    $$$$$ $$$
    $$$$$$$$
    $$$$$$


    and


    THE FACE OF "BOB" (SMALL VERSION) 12-13-90

    @@@@@@@^^~~~~~~~~~~~~~~~~~~~~^@@@@@@@@@
    @@@@@@^ ~^ @ @@ @ @ @ I ~^@@@@@@
    @@@@@ ~ ~~ ~I @@@@@
    @@@@' ' _,w@< @@@@
    @@@@ @@@@@@@@w___,w@@@@@@@@ @ @@@
    @@@@ @@@@@@@@@@@@@@@@@@@@@@ I @@@
    @@@@ @@@@@@@@@@@@@@@@@@@@*@[ i @@@
    @@@@ @@@@@@@@@@@@@@@@@@@@[][ | ]@@@
    @@@@ ~_,,_ ~@@@@@@@~ ____~ @ @@@
    @@@@ _~ , , `@@@~ _ _`@ ]L J@@@
    @@@@ , @@w@ww+ @@@ww``,,@w@ ][ @@@@
    @@@@, @@@@www@@@ @@@@@@@ww@@@@@[ @@@@
    @@@@@_|| @@@@@@P' @@P@@@@@@@@@@@[|c@@@@
    @@@@@@w| '@@P~ P]@@@-~, ~Y@@^'],@@@@@@
    @@@@@@@[ _ _J@@Tk ]]@@@@@@
    @@@@@@@@,@ @@, c,,,,,,,y ,w@@[ ,@@@@@@@
    @@@@@@@@@ i @w ====--_@@@@@ @@@@@@@@
    @@@@@@@@@@`,P~ _ ~^^^^Y@@@@@ @@@@@@@@@
    @@@@^^=^@@^ ^' ,ww,w@@@@@ _@@@@@@@@@@
    @@@_xJ~ ~ , @@@@@@@P~_@@@@@@@@@@@@
    @@ @, ,@@@,_____ _,J@@@@@@@@@@@@@
    @@L `' ,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    The holy visage of "Bob" Dobbs is copyright 1990, and probably other
    years as well - MAYBE EVEN YEARS YOU WON'T FIND IN YOUR PINK CALENDAR!
    - by the Church of the SubGenius. Fnord.

    (Note that the face of J.R. ``Bob'' Dobbs is a registered trademark of
    the Church of the SubGenius. Fnord.)

    lanny@niggasin:~$




    The former, ">>" as well as other bash reserved symbols are never read as arguments. If you want to pass >> as an argument you need to wrap it in quotes.

    well that seems easy enough.
  8. #8
    SBTlauien African Astronaut
    Problemo solved.
  9. #9
    Sophie Pedophile Tech Support
    Still gonna' make a shellscript just to see if i can. I'll even add some kewl options and shit to make it fancy.
Jump to Top