I'm trying to display Conkys process uptime. If I type the following into the terminal one line at a time it all works and I get the result I'm after.
getPID=$(pgrep -f conky)
conkyPID=$(ps -p $getPID -o etime=)
echo $conkyPID
Naive me thought a bash script would look like this.
#!/bin/bash
getPID=$(pgrep -f conky)
conkyPID=$(ps -p "$getPID" -o etime=)
echo "$conkyPID"
I've asked a couple of friends and the most helpful info I received was I need a command line separator and I think it's a |
.
I've tried a lot of variations of brackets, quotes and pipes to no avail.
In my experimenting it appears the 2nd line has no idea I have set the variable "getPID" in the previous line.
When I run the script I get.
error: process ID list syntax error
Output of running script with bash -x
:
ricky@Shitmobile:~$ bash -x conkypid.sh
++ pgrep -f conky
+ getPID='45990
153098'
++ ps -p '45990 153098' -o etime=
error: process ID list syntax error