Help with a script that involves processes

Hi everyone!

I need to create a bash script that allows me to copy in a file named report_<date>_<time>.csv the list of active processes.

<date> and <time> are the date and the time of the system when you create the file .csv

How can I create that? I have no idea how to do it :confused:

Thanks a lot

Please provide sample-data with sensitive data stripped off(if necessary), show the desired output, explain the steps how you want the data to be created and show the steps you did yourself so far. Please use

```text
 ... 
```
  • Tags to make your code easily readable for potential helpers.

I just need to create a file with the list of active processes until the file himself his killed. The choises are made from a menu in another bash file. I'm not sure how to do it beacuse I'm new in shell scripting.

The output in file csv will be, for example:

(name of file: report_20170318_123027.csv)

user1;19;ps;12:23:25;0:00:03
user2;53;firefox;13:00:13;0:03:40
user3;99;vim;13:22:53;1:00:25
user1;130;firefox;12:00:24;3:00:41
...

In the .csv file every line in composed by: user;pid;command;start;cputime but I know how to cut every information to compose every line. The only thing i need is to know how can i copy active processes in a file named like this.

The difficulty for me is to understand the commands i must use to:

  • copy the list of active processes in a file
  • name the file with date and time like i explain before

Is this a homework assignment? Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost in the Homework & Coursework Questions forum.

In particular: i have a menu with different choises. Every choise is a script.

The choise number 1 is: saving the list of active processes on the pc. The script periodically saves them (using sleep command) in a .csv file named report_<date>_<time>.csv.
<date> and <time> are the date and the time of the system when you create the file .csv

Every line of the .csv file reports an active process. For every process must be specify the following information, in this order:
{ USER; PID; COMMAND; START TIME; CPU TIME }
COMMAND : name of the process without parameters
START TIME : "HH:MM:SS"
CPU TIME : [DD-]hh:mm:ss

---------- Post updated at 09:25 AM ---------- Previous update was at 09:23 AM ----------

It's not an homework for school, i'm tring to do a program to understand how processes commands works and also i/o redirection, but i have some difficulties :frowning:

Until you answer the questions raised in post #3 in this thread, you will not get any more help.

We take cheating on homework assignments very seriously!

1 Like

Then show us what you have tried and explain what you are unable to figure out.

If you show us what you have tried, we'll all have a much better understanding of where you are stuck and have a better chance of helping you expand on what you have already learned.