Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Output Script Result to Log

  1. #1
    Join Date
    Mar 2006
    Beans
    1,123

    Output Script Result to Log

    Hi there,

    Is there a way to write the results of the script below to a log file?

    The script is made for OS X but I will probably be able to figure out how to do it once I know the Linux way.

    Thanks in advance!

    Code:
    #!/bin/bash
    
    # this should find all users currently logged in 
    users=( `who | awk '{print $1}' | sed '/^root$/d' | uniq` )
    
    for user in "${users[@]}"; do
        # find the homedir
        homedir=/Users/$user
        find $homedir/Library/Caches -name "*AdobeFnt*" -delete
    done
    "I'd rather be hated for what I am, than loved for what I'm not."

  2. #2
    Join Date
    Oct 2005
    Location
    Davao, Philippines
    Beans
    4,830

    Re: Output Script Result to Log

    Code:
    ./script.sh > my.log

  3. #3
    Join Date
    Mar 2006
    Beans
    1,123

    Re: Output Script Result to Log

    Quote Originally Posted by loell View Post
    Code:
    ./script.sh > my.log
    OS X moved from Cron to Launchd. Basically the command is put in a xml plist which looks like this:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    	<key>Label</key>
    	<string>ClearFontCache</string>
    	<key>ProgramArguments</key>
    	<array>
    		<string>sh</string>
    		<string>/Library/ITScripts/clean_font_cache.sh</string>
    	</array>
    	<key>RunAtLoad</key>
    	<true/>
    </dict>
    </plist>
    Should I change

    <string>/Library/ITScripts/clean_font_cache.sh</string>

    to

    <string>/Library/ITScripts/clean_font_cache.sh > my.log</string>

    ?
    "I'd rather be hated for what I am, than loved for what I'm not."

  4. #4
    Join Date
    Mar 2006
    Beans
    1,123

    Re: Output Script Result to Log

    Quote Originally Posted by OffHand View Post
    Should I change

    <string>/Library/ITScripts/clean_font_cache.sh</string>

    to

    <string>/Library/ITScripts/clean_font_cache.sh > my.log</string>

    ?
    Tried it but that does not work. Is there a way to put it in the script itself instead of the command?
    "I'd rather be hated for what I am, than loved for what I'm not."

  5. #5
    Join Date
    Mar 2006
    Beans
    1,123

    Re: Output Script Result to Log

    I finally managed to make the script write to a log file but unfortunately the file is empty. This should be easy to fix. I have added "echo >> /home/user/testlog.txt" to the script like posted below.

    [code]
    #!/bin/bash

    # this should find all users currently logged in
    users=( `who | awk '{print $1}' | sed '/^root$/d' | uniq` )

    for user in "${users[@]}"; do
    # find the homedir
    homedir=/Users/$user
    find $homedir/Library/Caches -name "*AdobeFnt*" -delete
    echo >> /home/user/testlog.txt
    done
    "I'd rather be hated for what I am, than loved for what I'm not."

  6. #6
    Join Date
    Jan 2006
    Location
    Philadelphia
    Beans
    4,076
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: Output Script Result to Log

    Code:
    #!/bin/bash
    
    # this should find all users currently logged in 
    users=( `who | awk '{print $1}' | sed '/^root$/d' | uniq` )
    
    for user in "${users[@]}"; do
        # find the homedir
        homedir=/Users/$user
        find $homedir/Library/Caches -name "*AdobeFnt*" -delete >> /home/user/testlog.txt
    done
    echo >> bla puts a newline into the file and nothing else. so append the >> to the find command, if you want the output of find to be in the file.

  7. #7
    Join Date
    Mar 2006
    Beans
    1,123

    Re: Output Script Result to Log

    For some reason that generates an empty log file even though the files were deleted

    Edit: I assume that there is nothing to log because the files that were found are already deleted. It would be great though if it could log what has been deleted.

    Any ideas?
    Last edited by OffHand; August 5th, 2008 at 04:55 PM.
    "I'd rather be hated for what I am, than loved for what I'm not."

  8. #8
    Join Date
    Apr 2007
    Beans
    68

    Re: Output Script Result to Log

    All you need to do is sit back, relax and allow someone else's code do it for you by the mere use of the commandline option -fprint:


    Code:
    find $homedir/Library/Caches -name "*AdobeFnt*" -fprint logfile -delete

  9. #9
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Output Script Result to Log

    Building on ABCC's suggestion, you can also print some more descriptive messages like this. This will also not truncate the logfile each run.
    PHP Code:
    #!/bin/bash

    # this should find all users currently logged in
    users=( `who | awk '{print $1}' | sed '/^root$/d' | uniq` )

    for 
    user in "${users[@]}"; do
      
    # find the homedir
      
    homedir=/Users/$user
      find $homedir
    /Library/Caches -name "*AdobeFnt*" -printf "`date`: Removing %p\n" -delete
    done 
    >> /home/user/testlog.txt 

  10. #10
    Join Date
    Mar 2006
    Beans
    1,123

    Re: Output Script Result to Log

    I'll try that tomorrow and let you know. Thanks!
    "I'd rather be hated for what I am, than loved for what I'm not."

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

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