PDA

View Full Version : Bash script question



i8163264128
July 25th, 2011, 12:34 PM
what I tried to do is make a script that prints the id of the longest running process with a particular label, what I came up with is :


#!/bin/bash

ps -elfo pid,etime | grep "$1$" | sort -r -k 2,2 | head -n 1 | awk '{print $1;}'

but (perhaps unsurprisingly) it does nothing... can anyone give me some advice here?

/noob

Vaphell
July 25th, 2011, 02:19 PM
ps -elfo pid,etime
ERROR: Conflicting format options.

your first step fails, try
ps efo pid,etime

Habitual
July 25th, 2011, 03:57 PM
It's always going to be 'init' (1).