shell script basic question

This is a discussion on shell script basic question within the Linux Programming forums, part of the Platform Specific Boards category; i am usaing a cronjob to run a database backup script. i added the line Code: cd /path/to/myscript.sh to the ...

  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
    32,854
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 06: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, 01:04 AM
  5. Arguements with a shell script
    By Doh in forum Linux Programming
    Replies: 1
    Last Post: 11-28-2002, 02:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21