Execute several command in linux shell file [closed]
Execute several command in linux shell file [closed]
I only can get the desire output when I run the command one by one. How can I combine all the command in a shell script and get the desired output?
//insert timestamp column
$ vmstat -n 5 | (while read; do echo "$(date +%Y-%m-%d.%H:%M:%S) $REPLY"; done)> vm.txt
//remove 1st & 2nd row
$ sed '1,2d' vm.txt > vm2.txt
//convert text file to csv
$ sed 's/^ *//;s/ */,/g' vm2.txt > vm2.csv
//insert column name
$ echo $'datetime, r, b, swpd, free, buff, cache, si, so, bi, bo, in, cs, us, sy, id, wa, st' | cat - vm2.csv> chart.csv
$ psql -p 5432 -U postgres -c "copy vmstat FROM '/root/report/chart.csv' delimiter '|' csv header"
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
I can't get the csvfile
– Fayne
Jul 2 at 2:37
Why can't you get the csvfile?
– that other guy
Jul 2 at 2:42
I don't know. I think maybe I didn't combine the command properly. Can you help me with the command?
– Fayne
Jul 2 at 2:58
Also see How to use Shellcheck, How to debug a bash script? (U&L.SE), How to debug a bash script? (SO), How to debug bash script? (AskU), Debugging Bash scripts, etc.
– jww
Jul 2 at 3:08
Where are you stuck?
– that other guy
Jul 2 at 2:30