Thread: shell script basic question

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    42

    shell script basic question

    i am usaing a cronjob to run a database backup script.

    i added the line
    Code:
    cd /path/to/myscript.sh
    to the beggining of the script so the output .sql file stays in the corrent directory.

    this works but is not practical... i would like to have a script that whatever i put it would send the output to the current path...

    so basicaly i need to know.

    how do i get the current path? should be some environment varible right?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    All sorts of ways

    here=`pwd`
    Gets the current directory

    here=`dirname $0`
    Gets the relative path from here to the program being executed

    Then there's $HOME, but that might depend on who the effective user is.

    You could try creating a cron job which just contains
    env
    to dump out the entire environment which your cron job sees.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A basic shell question
    By AngKar in forum C# Programming
    Replies: 1
    Last Post: 06-20-2006, 05:18 PM
  2. Basic C question ---- URGENT
    By x135 in forum Linux Programming
    Replies: 3
    Last Post: 03-25-2006, 11:05 PM
  3. Visual Basic Question
    By Xeavor in forum Tech Board
    Replies: 5
    Last Post: 12-02-2004, 09:59 AM
  4. Running 'exec' twice in one UNIX shell script
    By Zughiaq in forum Tech Board
    Replies: 2
    Last Post: 05-03-2003, 12:04 AM
  5. Arguements with a shell script
    By Doh in forum Linux Programming
    Replies: 1
    Last Post: 11-28-2002, 02:20 PM