Announcement

Collapse
No announcement yet.

I need a little help with a #! /bin/sh script

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    I need a little help with a #! /bin/sh script

    Hello,
    I would like to know how to check if file exists (i need this part with my script)
    I tried using google, but haven't found anything that would help.

    here is the script I tried to write
    Code:
    #! /bin/sh
    ### By Gediminas
    # 2007
    
    # First USB port
    echo "Mounting Device"
    #if -f /dev/sda1
    #then
     #if -d /media/usb
     #then echo "Already exist"
     #else sudo mkdir /media/usb
     #fi
    sudo mount /dev/sda1 /media/usb
    kdesu konqueror /media/usb
    sudo umount /media/usb
    # Second USB port
    #elif -f /dev/sdb1
    #then
     #if -d /media/usb
     #then echo "Already exist"
     #else sudo mkdir /media/usb
     #fi
    sudo mount /dev/sdb1 /media/usb
    kdesu konqueror /media/usb
    sudo umount /media/usb
    #else echo "Device not found"
    #fi
    exit
    I commented the parts that were preventing int from running at all

    This script should do the following:
    when i plug in my USB device (MP3 player, or flash drive) the script checks if /dev/sda1 exists
    if yes, it mounts it on /media/usb (if it exists, else creates this directory).
    If /dev/sda1 doesn't exist then it should check if /dev/sdb1 exists and mount it on /media/usb .

    now I don't know how to check that.
    I tried using
    Code:
    if exist /dev/sda1
    Like in DOS. It didn't work
    Code:
    if /dev/sda1
    I thougt this might work
    Code:
    if /dev/sda1 =! 0
    another bad idea
    Code:
    if -f /dev/sda1
    i found this in google, but it doesn't work either.

    Can anyone help me with this silly script?
    Join the dark side<br />---------------------------------------------------------------------<br />Samsung NC10 netbook running<br />PCLinuxOS 2010 // Win XP

    #2
    Re: I need a little help with a #! /bin/sh script

    http://tldp.org/LDP/Bash-Beginners-G...ect_07_01.html

    (as applicable to the Dash shell your script is actually referring to)

    Comment


      #3
      Re: I need a little help with a #! /bin/sh script

      Originally posted by UnicornRider
      http://tldp.org/LDP/Bash-Beginners-G...ect_07_01.html

      (as applicable to the Dash shell your script is actually referring to)
      Thanks, now I understand and my script works!

      Code:
      #! /bin/bash
      ### By Gediminas
      # 2007
      
      #check if /media/usb exists
      echo "Cheking media ..."
      if [ -d /media/usb ]
      then echo "ok"
      else sudo mkdir /media/usb
      fi
      
      # First USB port
      echo "Mounting Device..."
      if [ -b /dev/sda1 ]
      then
      sudo mount /dev/sda1 /media/usb
      kdesu konqueror /media/usb
      sudo umount /media/usb
      
      # Second USB port
      elif [ -b /dev/sdb1 ]
      then
      sudo mount /dev/sdb1 /media/usb
      kdesu konqueror /media/usb
      sudo umount /media/usb
      else echo "Device not found"
      fi
      exit
      Join the dark side<br />---------------------------------------------------------------------<br />Samsung NC10 netbook running<br />PCLinuxOS 2010 // Win XP

      Comment

      Working...
      X