Freelancer: nbazzeghin
Del:
Anmeld Indlæg

One liner using find and perl

If you have perl installed and in your path then this command should work for you: qwinsta.exe | find /I "active" | perl -ne "push @activeUsers, qq{$2} if /^.(\S+)\s+(\S+)/; END {if (@activeUsers == grep { $_ eq \"myusername\"} @activeUsers) { print 'Run Your Command here: IE system(\"dir\")'}}"

Konkurrenceindlæg #1 for Windows SHORT One-Liner Script CONTEST can use native versions of gawk sed cut etc and/or perl or dos batch etc, Systems Admin SysAdmin contest

Offentlig Præciserings Opslagstavle

  • nbazzeghin
    nbazzeghin
    • 2 måneder siden

    for OR its $_ eq \"myusername\" || $_ eq \"myotherusername\"

    • 2 måneder siden
  • jvirt
    Konkurrenceafholder
    • 2 måneder siden

    freelancer website annoying

    • 2 måneder siden
  • nbazzeghin
    nbazzeghin
    • 2 måneder siden

    well @ is just for an array in perl. this little guy guys takes the user names and puts them in an array and then checks every item in the array. If they all equal myusername then it runs the print "Your Command here..." block, if not, it just quits

    Yea I know its a little hard to read, I had to double check a couple of my things to see if there was an easier way, but this way was a bit more concise to be in line with the "one-liner" requirment

    • 2 måneder siden