rleyba828
asked on
Assistance with bash, include command in output to a file
Hi Team,
I just need to create a simple script that captures some commands and output to a file. In my code below, it is just sending the actual outputs and not the command itself, making it difficult to note the start and end output stream of each command. In the example below, I just have 5 shell commands....in the final script, there will be over 50.
The file just shows the raw output of the individual commands, and not the commands that invoked them, making it difficult to find the start and end of each output block.
Thanks very much.
I just need to create a simple script that captures some commands and output to a file. In my code below, it is just sending the actual outputs and not the command itself, making it difficult to note the start and end output stream of each command. In the example below, I just have 5 shell commands....in the final script, there will be over 50.
[root@testing ~]# cat baseline.sh
#!/bin/bash
BASEFILE=BASELINE_$(date '+%d_%b_%Y_%H_%M_%S').txt
uptime >> $BASEFILE 2>&1
who >> $BASEFILE 2>&1
last -n 100 >> $BASEFILE 2>&1
free -m >> $BASEFILE 2>&1
df -h >> $BASEFILE 2>&1
The file just shows the raw output of the individual commands, and not the commands that invoked them, making it difficult to find the start and end of each output block.
[root@testing ~]# cat BASELINE_26_Apr_2015_09_43_46.txt
09:43:46 up 1:16, 4 users, load average: 0.00, 0.00, 0.00
au157 tty1 2015-04-26 18:47 (:0)
au157 pts/0 2015-04-26 18:47 (:0.0)
au157 pts/1 2015-04-26 08:48 (192.168.76.1)
au157pts/2 2015-04-26 09:01 (192.168.76.1)
wtmp begins Sun Apr 26 09:39:02 2015
total used free shared buffers cached
Mem: 1894 618 1275 4 60 325
-/+ buffers/cache: 232 1662
Swap: 4063 0 4063
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_k2dot0-lv_root
35G 4.1G 30G 13% /
tmpfs 948M 80K 948M 1% /dev/shm
/dev/sda1 477M 68M 385M 15% /boot
Thanks very much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER