2

Does there exist a dummy command in Linux, that doesn't change the input and output, and takes arguments that doesn't do anything?

cmd1 | dummy --tag="some unique string here" | cmd2

My interest in such dummy command is to be able to identify the processes, then I have multiple cmd1 | cmd2 running.

Jasmine Lognnes
  • 6,597
  • 9
  • 38
  • 58

4 Answers4

3

You can use a variable for that:

cmd1 | USELESS_VAR="some unique string here" cmd2

This has the advantage that Jonathan commented about of not performing an extra copy on all the data.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
1

To create the command that you want, make a file called dummy with the contents:

#!/bin/sh
cat

Place the file in your PATH and make it executable (chmod a+x dummy). Because dummy ignores its arguments, you may place any argument on the command line that you choose. Because the body of dummy runs cat (with no arguments), dummy will echo stdin to stdout.

Alternative

My interest in such dummy command is to be able to identify the processes, then I have multiple cmd1 | cmd2 running.

As an alternative, consider

pgrep cmd1

It will show a process ID for every copy of cmd that is running. As an example:

$ pgrep getty
3239
4866
4867
4893

This shows that four copies of getty are running.

John1024
  • 109,961
  • 14
  • 137
  • 171
1

I'm not quite clear on your use case, but if you want to be able to "tag" different invocations of a command for the convenience of a sysadmin looking at a ps listing, you might be able to rename argv[0] to something suitably informative:

$:- perl -E 'exec {shift} "FOO", @ARGV' sleep 60 &
$:- perl -E 'exec {shift} "BAR", @ARGV' sleep 60 &
$:- perl -E 'exec {shift} "BAZ", @ARGV' sleep 60 &
$:- ps -o cmd=
-bash
FOO 60
BAR 60
BAZ 60
ps -o cmd

You don't have to use perl's exec. There are other conveniences for this, too, such as DJB's argv0, RedHat's doexec, and bash itself.

Community
  • 1
  • 1
pilcrow
  • 56,591
  • 13
  • 94
  • 135
0

You should find a better way of identifying the processes buy anyway, you can use:

ln -s /dev/null /tmp/some-unique-file
cmd1 | tee /tmp/some-unique-file | cmd2
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • Many hundreds GB of data will go through the pipe, so writing it to a file is no good. – Jasmine Lognnes Nov 09 '14 at 03:52
  • 2
    @JasmineLognnes: Make the `/tmp/some-unique-file` into a symlink to `/dev/null`. But it is still a tad painful. But then, introducing a process into the middle of the command line like that imposes an enormous overhead (an extra pipe, with extra copying of all the data). Why not modify `cmd1` and `cmd2` to take the dummy arguments? – Jonathan Leffler Nov 09 '14 at 04:13