Combining two linux commands

1

Im trying to use mergecap to merge 15 old pcap files in a folder. I tried to use

FILES=($(find /mnt/md0/capture/DCN/ -maxdepth 1 -type f -name "*.pcap"  -print0 | xargs -0 ls -lt | tail -15 | awk '{print $8}'))

and use mergecap command as mergecap -w Merge.pcap ${FILES[@]} but the mergecap doesnt run when I put it on crontab. Is there any method to combine these two commands to work properly.

Jishnu U Nair

Posted 2014-02-06T12:36:06.973

Reputation: 263

Does it run from the CLI? – MariusMatutiae – 2014-02-06T12:41:14.373

yes, it works from terminal perfectly.. and I checked all path in the crontab, everything is fine, In syslog it shows that a mail is send just after execution. – Jishnu U Nair – 2014-02-06T12:48:28.427

are you running the crontab as root, or as normal user? – MariusMatutiae – 2014-02-06T12:51:35.223

normal user. But I have put the script in sudo crontab -e – Jishnu U Nair – 2014-02-06T12:55:37.447

try switching the script to the normal user's crontab. Or, alternatively, leave the script in sudo's crontab, but debug it as sudo. The two options are distinct, you should try both of them. – MariusMatutiae – 2014-02-06T12:58:01.500

You're not quoting "${FILES[@]}"? – terdon – 2014-02-06T15:47:59.673

@terdon In the mergecap command? no i dint quote – Jishnu U Nair – 2014-02-06T20:10:13.420

I've never used mergecap but that might be a possible problem, you should always quote shell variables when expanding, just in case (see suspectus's answer). – terdon – 2014-02-06T20:14:13.207

Answers

0

try using printf to split the array into separate lines:

mergecap -w Merge.pcap $(printf -- '%s\n' "${FILES[@]}") 

suspectus

Posted 2014-02-06T12:36:06.973

Reputation: 3 957