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

  • Home
  • SEARCH
  • 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 6115753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:07:40+00:00 2026-05-23T15:07:40+00:00

I am coping some file,So, the result can be either way. eg: >cp -R

  • 0

I am coping some file,So, the result can be either way.

eg:

>cp -R bin/*.ksh ../backup/

>cp bin/file.sh ../backup/bin/

When I execute above commands, its getting copied. No response from the system, if it copied successful. If not, prints the error or response in terminal itself cp: file.sh: No such file or directory.

Now, I want to log the error message, or if it successful I want to log my custom message to a file. How can I do?

Any help indeed.

Thanks

  • 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-05-23T15:07:41+00:00Added an answer on May 23, 2026 at 3:07 pm

    try writing this in a shell script:

    #these three lines are to check if script is already running.
    #got this from some site don't remember :(
    
    ME=`basename "$0"`;
    LCK="./${ME}.LCK";
    exec 8>$LCK;
    
    LOGFILE=~/mycp.log
    
    if flock -n -x 8; then
    
        # 2>&1 will redirect any error or other output to $LOGFILE
    
        cp -R bin/*.ksh ../backup/ >> $LOGFILE 2>&1
    
        # $? is shell variable that contains outcome of last ran command
        # cp will return 0 if there was no error
        if [$? -eq 0]; then
           echo 'copied succesfully' >> $LOGFILE
        fi
    fi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to read a file's data but continue reading the data
I'm having some trouble getting log4net to work from ASP.NET 3.5. This is the
I'm working on a web app that can allow the user to input some
I can copy a node from one XML file to another using org.w3c.dom.Document. importNode(Node
I'm coding some ActionScript 3 app that needs to request some HTML page and
I am currently coding some chat program and now want to play music via
I have an application developed in Grails 2.0.4, I am hard coding some of
I'm currently working on some coding for a hotel booking widget and am using
I've noticed in some coding people use icicle with the onCreate method, and I
I've been messing around with some coding and finally think I'm finally ready for

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.