Wednesday 11 November 2015

sudo su as

Type 1:

cat ScriptFile
whoami
sudo su - user2 <<EOF
whoami
EOF


$ ssh user1@RemoteHost 'bash -s' < ScriptFile 

Output:
user1
user2
Stderr: Pseudo-terminal will not be allocated because stdin is not a terminal.



using pssh:
[ in this approach: (-l)  no need to copy file to remote host to run the command. ]

$ pssh -i -H RemoteHost -l user1 -o OutPutDir -I 'bash -s'< ScriptFile 

[1] 19:28:14 [SUCCESS] RemoteHost
user1
user2

$ pssh -i -H RemoteHost -l user1 -o OutPutDir -I < ScriptFile 

Output:
[1] 19:27:30 [SUCCESS] RemoteHost
user1
user2
Stderr: Pseudo-terminal will not be allocated because stdin is not a terminal.


NOTE: [ quick pssh help]


-h HOST_FILE, --hosts=HOST_FILE
-H HOST_STRING, --host=HOST_STRING
-l USER, --user=USER  username (OPTIONAL) [ small l ]
-p PAR, --par=PAR     max number of parallel threads (OPTIONAL)
-o OUTDIR, --outdir=OUTDIR
-i, --inline          inline aggregated output and error for each server

-I, --send-input      read from standard input and send as input to ssh [ caps i ]


pssh -i -h hosts.txt -l user1 o OutputDir -I 'bash -s' < ScriptFile

pssh -h hosts.txt -l irb2 -o /tmp/foo uptime


Tuesday 10 November 2015

perl html5 video page gen code

#!/usr/bin/env perl

print ("<!DOCTYPE html>\n");
print ("<html>\n");
print ("<body>\n");

my @files = `ls *.mp4`;

foreach $a (@files) {
    print ("<video width=\"320\" height=\"240\" controls>\n");
    print ("<source src=\"$a\" type=\"video/mp4\">\n");
    print ("</video>\n");
}

print ("</body>\n");
print ("</html>\n");