I have a task in which I have to analyze a file transfer between a ftp client and a server.

I know about htop command.

If the file transfer takes 15 secs, then I want the htop command to run each second untill the file transfer is finished and direct the output to a file so that I can analyze the process. But I cannot think of any method which can get htop running each second.

Also, the output of htop command prints is not in human-readable form.

  • 1
    You can use watch command. – 69 420 1970 Feb 5 '20 at 18:04
  • Can I use it to store the output in file – Vipul Tyagi Feb 5 '20 at 18:05

First off be sure that there isn't an easier way to get the information you want there are a lot of other tools out there that may work better, and htop doesn't go to files well. See: https://stackoverflow.com/questions/17534591/htop-output-to-human-readable-file although there is a kludge here: https://askubuntu.com/questions/726333/how-to-save-htop-output-to-file if you can't find something.

What is it in htop that you can't get out of ps or some of the other tools designed for command line output and parsing?

Then write a script something like this (untested):


my_log="ftp_$(date +%Y%m%d%H%M%S).log"
$(command to start the ftp 2>&1 > "$my_log")& 

sleep 15
while [[ $still_there -gt 0 ]]
    if [[ $(ps ax | grep $my_pid | grep -v grep) ]] # If your PID is still in the process table
        # Insert monitoring stuff in here that > to $my_log
    sleep 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.