US Military Gamers - Powered by vBulletin


Results 1 to 6 of 6
  1. #1
    USMG [Retired Staff] Member

    Join Date
    Nov 2011
    Location
    Laughlin AFB
    Posts
    10,435
    First Name
    Sam
    Branch
    Airforce

    Bash script deletes computer (or, the dangers of su)

    So I was writing a Makefile for a VideoServer to install the web interface pages. The Makefile had the typical rules - all, clean, install, uninstall. To uninstall, it needed to remove all the executables from a certain directory /var/www (this is on Linux, btw). However, it needed to be dynamic in that it should be able to tell what distro of Linux it was running and set a path variable accordingly, since there are different places the files go in different distributions. So I wrote a bash script for inside the Makefile to set this path variable. The clean rule was like this:
    rm -r ${installdir)/*
    Some of you probably already see where this is going. Needless to say, the installdir variable never got set, and held an empty value. Big problem was, the install/uninstall options had to be run as super user in order to write/delete to those particular locations. Well, it started removing files, just the wrong ones. For those of you who don't use Linux, the top-level directory is "/". This holds all the folders needed for the OS, programs, and your files. EVERYTHING is in this folder. The * in this case acts as a wildcard and means 'all files' and the -r option for the rm command (remove) means recursively, or go into all subfolders and delete those too (still not sure why the -r option was set). So it did exactly what I told it to - "rm -r /*", or my entire filesystem.
    Moral of the story is, be careful with su and rm. Even a simple Makefile can cause lots of problems.

  2. #2
    Tim's Bromance Partner

    Join Date
    Sep 2009
    Location
    In the ether between websites
    Posts
    2,643
    First Name
    Ben
    Branch
    Army
    bash scripts can either be a life saver, or your worst nightmare. Depending on your point of view.
    "Necessity is the plea of every infringement of human freedom. It is the argument of tyrants, it is the creed of slaves"

    William Pitt, 1783



  3. #3
    Silent but Deadly....

    Join Date
    Apr 2010
    Location
    Davenport, Iowa
    Posts
    1,747
    Branch
    Marines
    sudo doooooh'!!!!
    [SIGPIC]http://forums.usmilitarygamers.com/attachment.php?attachmentid=3616&d=1341691069[/SIGPIC]

    Silent But Deadly!

  4. #4
    Tim's Bromance Partner

    Join Date
    Sep 2009
    Location
    In the ether between websites
    Posts
    2,643
    First Name
    Ben
    Branch
    Army
    Quote Originally Posted by XxSILENTxFARTxX View Post
    sudo doooooh'!!!!
    sudo make me a sandwich....bitch
    "Necessity is the plea of every infringement of human freedom. It is the argument of tyrants, it is the creed of slaves"

    William Pitt, 1783



  5. #5
    USMG [Retired Staff] Member

    Join Date
    Nov 2011
    Location
    Laughlin AFB
    Posts
    10,435
    First Name
    Sam
    Branch
    Airforce
    Quote Originally Posted by saviger View Post
    bash scripts can either be a life saver, or your worst nightmare. Depending on your point of view.
    Yeah, I've been much more careful simce this incident.


  6. #6
    USMG [Retired Staff] Member

    Join Date
    Apr 2010
    Location
    Not Chicago
    Posts
    1,895
    First Name
    Justin
    Branch
    Marines
    heh yeah su is a different world than Windoze's Admin.

    You can rain down some pretty awesome hate and content on yourself as su.
    Steam: raging_clue | Battle.net: Ragingclue#1192 | Origin: Ragingklu | PSN: Ragingklu
    My war story: One time at Al Asad they ran out of steak and crab legs before I got to the chow hall. Oh the horror. Then I hit the rack. The end.

Similar Threads

  1. How NOT to Get a Movie Script Submitted
    By River_Rat_459 in forum Scuttlebutt
    Replies: 1
    Last Post: 08-15-2011, 22:54
  2. [PC] old computer games
    By toby2533 in forum General Chatter
    Replies: 0
    Last Post: 11-05-2010, 10:36
  3. looking for gaming computer
    By InkaB0DpaiN in forum Tech Talk
    Replies: 3
    Last Post: 05-04-2010, 11:05

Tags for this Thread

Posting Permissions

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