Skip to content

Instantly share code, notes, and snippets.

@oldkingcone
Created October 12, 2017 01:06
Show Gist options
  • Select an option

  • Save oldkingcone/43460ddbeef137755005378e3479684d to your computer and use it in GitHub Desktop.

Select an option

Save oldkingcone/43460ddbeef137755005378e3479684d to your computer and use it in GitHub Desktop.
Returns user at run time, will log into seperate file and leave human readable date/time with real username and logged in username. Add line ' perl runuser.pl' to your bashrc file to have it run upon TTY/Shell interaction.
#! /usr/tmp/env perl
use strict;
use 5.010;
my $user = $ENV{USER};
my $logname = $ENV{LOGNAME};
my $file_directory = "./ranby.txt";
# my $second_log = "./second.txt";
my $filename = "ranby.txt";
# my $second = "second.txt";
my $timestamp = localtime(time);
# my $path = shift || '/';
# traverse($path);
# sub traverse {
# my @queue = @_;
#while (@queue) {
# my $thing = shift @queue;
#say $thing;
#next if not -d $thing;
#opendir my $dh, $thing or die;
#while (my $sub = readdir $dh) {
#next if $sub eq '.' or $sub eq '..';
#push @queue, "$thing/$sub";
# }
#closedir $dh;
#}
#return;
#}
open(my $filename, ">>", $file_directory) || die "cant open $file_directory: $!";
binmode($filename);
print $filename "$timestamp, by $user, on $logname\n";
close($filename) || die "cant close $file_directory: $! ";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment