13

I want to write batch or something, that will write output of top into a file on login.

I did top >> output-file, but it contains some strange character!

Can somebody give a simple tutorial about how to write batch file in Linux?

kenorb
  • 9,995
  • 2
  • 78
  • 90
Behzadsh
  • 3,893
  • 13
  • 35
  • 45

2 Answers2

19

Try the following

top -b -n1 > filename.txt

The -b is for batch mode, which should prevent the strange characters. The -n1 tells it to only print one iteration.

Mad Scientist
  • 686
  • 6
  • 19
1

Go to terminal and type:

user@ubuntu:~$ top > filename.txt

The output of top command will be now stored in a text file which is located in your Home directory.

See: Bash scripting Tutorial.

kenorb
  • 9,995
  • 2
  • 78
  • 90
karthick87
  • 80,647
  • 59
  • 193
  • 232