Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7784633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:07:34+00:00 2026-06-01T20:07:34+00:00

We have scripts of following nature (in cron) someScript.sh > /tmp/cronlog/somescript.$(date +%Y%m%d).log 2>&1 Now

  • 0

We have scripts of following nature (in cron)

someScript.sh > /tmp/cronlog/somescript.$(date +%Y%m%d).log 2>&1

Now is there a way by which with in someScript.sh I can figure out what file the output has gone in to?

The script sends email with summary. At the same time I would like to mention that details could be found in so and so output file – with in the email.

I am aware of the construct if [ -t 1 ] to detect stdout etc but how to get the output file name?
Note that I want this to be generic so that some one can change the output file in cron and the script does not need to be modified.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:07:35+00:00Added an answer on June 1, 2026 at 8:07 pm

    The simplest thing I could think is that:

    readlink -f /proc/$$/fd/1
    

    $$ is the PID of the script (inside the script). On most unix systems, /proc/[pid] is the pseudo-directory containing info for process [pid].

    /proc/[pid]/fd is a directory containing a list of symlinks for the open file-descriptors of the process. fd/0 is input, fd/1 is the output of the script, etc.

    readlink then gives you the target file or tty if you don’t redirect the output.

    Of course, if you want to display it, you have to display it somewhere else than standard ouput, or it will be redirected! To debug, try the std error (2).

    Various callings give those results on my box (script.sh just calls readlink -f /proc/$$/fd/1 >&2)

    # ./script.sh
    /dev/pts/0
    
    # ./script.sh > /var/tmp/foo
    /var/tmp/foo
    
    # ./script.sh | more
    /proc/12132/fd/pipe:[916212]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following rewrite set up: RewriteRule r/(.*) scripts/report.php?cp=1&id=$1 It works great to
I have two validation scripts which work in their own right, but I now
I'm a newbie in bash scripts and have the following problem : I'm trying
I have the following two php scripts remove_directory.php <?php start_session(); $userId = $_SESSION['userId']; exec(escapeshellcmd(rm
I have the following scenario in my TFS: MyTeamProject Trunc Sources Scripts Installations Prod
I have a lot of Perl scripts that looks something like the following. What
I have the following script which first shows only the first para of the
if have the following two scripts, when a button is clicked i wish for
I have 2 Python scripts which are main_menu.py and inputip.py. The problem occurs when
Lets say I have the following scripts a.sh echo in a if test 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.