Freelancer: nibb13
Anmeld Indlæg

Perl one-liner

One-liner is pretty simple: perl -e "my $c1=0;my $c2=1;foreach (`qwinsta`){$_=~/.+Active.*/ ? $_=~/.+myusername.*/ ? {$c1=1} : {$c2=0} : 0};$c1 && $c2 && print `dir C:\\`;" It works with hardcoded username. Can be changed to rely on currently logged-in username. Here's clarified version which shares the same logic: #!perl # Condition #1 - user "myusername" is "Active" (unmet by default) my $c1=0; #Condition #2 - any user except "myusername" is not active (met by default) my $c2=1; # Looping through lines of qwinsta output foreach (`qwinsta`){ # If line contains "Active" somewhere in the middle if ($_=~/.+Active.*/){ # If line contains "myusername" somewhere in the middle if ($_=~/.+myusername.*/){ # Set condition #1 to true (as active myusername found) $c1=1; } else { # Set condition #2 to false (as active other user found) $c2=0; } } } # If both conditions are true then run command in external shell and print output of it $c1 && $c2 && print `dir C:\\`;

Konkurrenceindlæg #5 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

  • jvirt
    • 1 måned siden

    difficult decision, i like your solution also, but I think your solution was harder for me to understand than the 1st contest submission, (your explanation helped thanks!) i may also have to give a tiny boost the first submission. (he even created his account same day he submitted solution to my contest.)

    • 1 måned siden
    1. nibb13
      • 1 måned siden

      No worries! 1st submission is sealed, but I had a chance to peek on it via screenshot. It looks cool to me. Thanks for the contest and your review!

      • 1 måned siden