+ Reply to Thread
Results 1 to 3 of 3

Thread: Bash Scripting: Automate Linux

  1. #1
    Tor
    Tor is offline Programming Expert
    Join Date
    Oct 2007
    Posts
    488
    Rep Power
    0

    Bash Scripting: Automate Linux

    Linux Scripting, Automate Linux

    Introduction:
    We all love Linux, but sometimes its a bit to much to handle all the hassle.

    Thats why I am going to handle Linux Scripting how.

    There are a couple of good scripting languages out there for Linux. They are bash, perl, python, awk and sed.


    Basic Scripting:

    I am going to handle Bash mostly now. Bash is the Basic scripting Language for the Bounce Again Shell.

    Bash can not to a much, but when you use grep and wget and curl you can make a really nice script.

    Quick tips
    Like: `cat /dev/urandom` will give you a Random number.

    Ah, isnt that great well like I said before Grep is great.

    Its great since you can figure-out if there is a text in the file. If you use that together with wget. You can check if a Pecific text on a webpage.


    Lets see a working script:

    Ok, lets have a look at this script: `history | awk '{print $2}'|sort |uniq -c |sort -n|cowsay|more`

    Lets dig into that. history gives the history of old used commands in Bash. we Pipe that (|) to the awk script: {print $2} that is print the Second Argument. lets continue. sort is.. well you guess. SORTING as we are still pasing the history over we sort history. Then we come at uniq -c.

    Thats a program that can put a list of Unique things in a list. Of the given argument. As we give a list of Sorted commands we used in the history we get a list with only Unique results. After that we will also notice that there is -c in there. That means Count the results. We Pass that to sort -n that means a Number sort. As there were numbers put before the names before since of the uniq -c thing we will see the thing that happened the most on top. and they go lower and lower all the time. That gets passed to cowsay.

    To make it look fun.

    And then we have our big friend more and that is so we can read our text. And it will not scroll and end.

    This all gets printed by print in the Awk part.

    And we get a output like:

    Code:
          5 cat
          5 mv
          9 htop
         11 man
         11 rm
         11 sudo
         40 vim
         66 ls
         82 cd
        104 exit

    Conclusion:
    The trick of using scripting in Linux is using other programs to do the tasks you want it to do.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Jordan Guest
    Bash scripting often comes in handy at my work. We use it for reporting, automation of tasks and man other things.

  4. #3
    Hektor is offline Programmer
    Join Date
    Jan 2007
    Posts
    126
    Rep Power
    0
    Not bad. Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 9
    Last Post: 07-09-2010, 11:03 PM
  2. Learning the linux command line - Bash
    By Coldhearth in forum Linux/Unix General
    Replies: 2
    Last Post: 02-10-2010, 05:39 PM
  3. Linux/Bash: Check if a file exists
    By Tor in forum Bash / Shell Scripting
    Replies: 4
    Last Post: 07-10-2009, 11:28 AM
  4. automate data transfer
    By Judor in forum C# Programming
    Replies: 3
    Last Post: 05-02-2009, 11:22 AM
  5. Automate emails
    By FACT0R in forum PHP Development
    Replies: 2
    Last Post: 08-21-2008, 10:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

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