Find the answer to your Linux question:
Results 1 to 2 of 2
I'm trying to make a script where the contents of a file are used as the trigger for what needs to be done I used to do it with running ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    1

    Bash script - switch on filecontent


    I'm trying to make a script where the contents of a file are used as the trigger for what needs to be done

    I used to do it with running a php script, but my new box doesn't have php on it (and putting it on is not an option)

    My php script:

    Code:
    $trigger = file_get_contents('trigger.txt')
    
    switch ($trigger)
    {
    case 'update':
     // update command
    break;
    case 'reset':
     // reset command
    break;
    default:
     // default command
    }

    Any suggestions to have a similar functionality in a bash script?

    Thanks
    KJ

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Code:
    #!/bin/bash
    trigger=$(cat trigger.txt)
    case $trigger in
      'update')
     # update command
      ;;
     'reset')
     # reset command
      ;;
      *)
     # default command
    esac
    exit $?

Posting Permissions

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