Results 1 to 6 of 6

Thread: How do I make a batch file executible?

  1. #1
    Join Date
    May 2007
    Beans
    43
    Distro
    Kubuntu 8.04 Hardy Heron

    How do I make a batch file executible?

    Hey folks: I've been trying to write a simple batch file, and get it to run. But I've yet to get it fixed to be executable. The file is:

    #apt-clean

    sudo apt-get update
    sudo autoremove
    sudo purge
    sudo autoclean
    sudo check

    The reason for this, is that after an update, or installing a program though apt-get, programs at times won't run. The indicator sits there and spins for about 20 or so seconds, then nothing. But I found by doing the above, it works. I got tired of having to type all that in, so a simple 1 click (or command) would be great.

    So how can I get this to work? I typed in:

    nano apt-clean
    typed in the stuff above
    saved it to the /home/kcredden directory
    But chmod hasn't worked right.

    Any ideas?

    Thanks

    - Kc

    using Kubuntu 8.04. (Not upgrading to V9 till it's more debugged.)
    --
    Kevin C. Redden
    kredden@maysville-21921- (DOT) com
    (remove the -21921- to e-mail me)

  2. #2
    Join Date
    Dec 2007
    Beans
    485
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: How do I make a batch file executible?

    probably need to give it a .sh extention

    chmod +x filename

    the run it by ./filename
    Last edited by wsonar; May 1st, 2009 at 11:32 PM.

  3. #3
    Join Date
    Mar 2005
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: How do I make a batch file executible?

    first off, I guess you mean sudo apt-get autoremove, etc. Secondly, you'd have to tell the script it should wait for one command to finish, then run the next one. And third, for a well formed script, you need to declare what shell you want to run it in. finally, skip the sudo here and run it with sudo. So this in your script:
    Code:
    #!/bin/bash
    apt-get update &&
    apt-get autoremove &&
    apt-get purge &&
    apt-get autoclean &&
    apt-get check
    Then make it executable with
    Code:
    chmod +x filename
    Then run it with
    Code:
    sudo ./filename
    Never use sudo if you do not absolutely have to.

  4. #4
    Join Date
    Mar 2008
    Location
    Deep South Texas, SpaceX
    Beans
    1,890
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: How do I make a batch file executible?

    I wrote the following script

    clean.sh

    the comments are to remind me of what I did,
    and where the code came from...

    all my scripts are in

    ~/bin/

    which is another trick I picked up from this forum...
    it separates my stuff from everything else.
    scripts placed there will be separated from any scripts that come with the original install, or are installed by other software...
    and it keeps directories a little cleaner/neater.

    I have desktop launchers to run these with just a double-click.

    The script must be made executable...


    Code:
    #!/bin/bash
    ## commands to clean drive of excess garbage
    ## from ubuntu forums
    ## http://ubuntuforums.org/showthread.php?t=1113381
    ## 01-april-09
    
    sudo apt-get autoremove
    
    sudo apt-get autoclean
    
    sudo apt-get clean
    
    sudo dpkg --configure -a

    No, the script is not perfect, or ideal...
    it's "quick and dirty", one of the first I wrote for myself...
    feel free to adapt, reuse, rewrite, delete, etc.

    As for too much sudo, soro2005 may have a point...
    I'm still too new to know about that...

    ErnestG
    "Free software is a matter of liberty, not price." -- Richard Stallman
    So don't forget to tip your software authors!

    I'm a Fireman... what's YOUR superpower?

  5. #5
    Join Date
    Dec 2008
    Location
    Littleton, Colorado USA
    Beans
    362
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: How do I make a batch file executible?

    During testing run the shell script using the following:

    sh -xv <shell-script>

    The -x will display to the screen each line as it is executed. The -v is verbose. Generally, just the -x is good enough, though if there are if's and case statements, the verbose will list all statements, but only show those that are executed. Also the <shell-script> doesn't have to have execute permissions. The "sh" above can be replace with bash, but if you do a "ls -la /bin/sh" you will notice that "sh" is a soft link to "bash".

    Once you set the script to +x, you can also add to the end of first line of the script "#!/bin/bash" an -vx. It will do the same thing as "sh -xv" or "sh -x".

    Hope this helps.

  6. #6
    Join Date
    May 2007
    Beans
    43
    Distro
    Kubuntu 8.04 Hardy Heron

    Re: How do I make a batch file executible?

    Wow, now that's service! . Thanks folks, got it running. Saves me a load of headaches.

    - Kc
    --
    Kevin C. Redden
    kredden@maysville-21921- (DOT) com
    (remove the -21921- to e-mail me)

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
  •