Find the answer to your Linux question:
Results 1 to 4 of 4
I am a linux newbie. At our company we have project directories such as /projects/0688, /projects/0689, etc. I can easily create a file with the directory names by: file called ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2004
    Posts
    2

    Piping? Redirect? Arguements? Script Help Please


    I am a linux newbie.

    At our company we have project directories such as /projects/0688, /projects/0689, etc. I can easily create a file with the directory names by:


    file called create_project_dir.sh
    '---------------------------------
    $FILE=temp.txt
    find /projects -maxdepth 1 -name '0*' -type d > $FILE
    '---------------------------------

    I want to know if anyone has modified any file in the directory in the last 200 days. If noone has modified the project - I would like an email to archive the project. This script file below does what I want for a single arguement I just don't know how to use the file above to automate the task.

    I want to use this file as an input to the following script.

    file called find_old_projects.sh
    '---------------------------------
    $PROJECT_DIR=$1
    $DAYS_NOT_USED=200

    find $PROJECT_DIR -mtime -$DAYS_NOT_USED -type d -print > $TESTFILE

    if [ -s $TESTFILE ] ; then
    echo "$PROJECT_DIR has been modified in the last $DAYS_NOT_USED days"
    else
    echo "$PROJECT_DIR has been NOT modified in the last $DAYS_NOT_USED days"
    cat $TESTFILE | mail -s ""$PROJECT_DIR has been NOT modified in the last $DAYS_NOT_USED days" someone@linux.com
    fi ;
    '---------------------------------

    I run the following command

    awk "{ print ; } test.txt | find_old_projects.sh

    What am I doing wrong? I think that I am missing something?

  2. #2
    Linux Guru
    Join Date
    Mar 2003
    Location
    Wisconsin
    Posts
    1,907
    I just don't know how to use the file above to automate the task.
    To automate the task, use cron. You can set it up to send you an e-mail just like you want.

    Happy scripting!
    Jeremy
    Registered Linux user #346571
    "All The Dude ever wanted was his rug back" - The Dude

  3. #3
    Just Joined!
    Join Date
    Jun 2004
    Posts
    2

    Thanks for the info, However,

    Jeremy1701

    My problem is that I am trying to feed a line in a file as an arguement ie.

    temp.txt contains

    /projects/0866
    /projects/0867
    /projects/0868

    I would like to feed each line as an arguement to a function or in this case a shell script called find_old_projects.sh. The function determines whether any file in the directory has been modified in the last 200 days and it emails me if none have been modified. Afterwhich I can archive if I want.

    My script works independently, however when I try to pipe the arguements in, it does not work.

    Thanks







    Quote Originally Posted by jeremy1701
    I just don't know how to use the file above to automate the task.
    To automate the task, use cron. You can set it up to send you an e-mail just like you want.

    Happy scripting!
    Jeremy

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Mar 2003
    Location
    Wisconsin
    Posts
    1,907
    I don't have my reference book handy, so I can't give you specifics. But I think maybe you're logic is wrong here.

    Assuming that temp.txt never changes location or ownership, you can re-write your script so that it always opens that file and parses out the data you want, rather then trying to pass it the values by awking them out.

    Something like

    Code:
    $file_path="/root/temp/temp.txt"
    ...
    Read in the contents of the file one line at a time, and  
    $PROJECT_DIR="current line"
    ...
    I hope that makes sense. If it doesn't, let me know.
    Jeremy
    Registered Linux user #346571
    "All The Dude ever wanted was his rug back" - The Dude

Posting Permissions

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