Wednesday, November 1, 2017

Bash for loop examples


Buy Moto series phones: Moto E, Moto G, Moto X or Other phones
Buy eBooks from Flipkart
-----------------------------------------------

For loop example in bash script:
To get yarn log files for multiple spark jobs, we can use this command.
for i in `cat appid.txt`; do echo $i; yarn logs -applicationId $i > sparkjob_01sep_logs/$i.log; echo "——"; done




For loop with sequence and ssh into multiple servers:
To login into multiple servers and run a command, we can use below command.

for i in `seq 101 125`;do ssh -q machinename$i "hostname;ls -ltr";done



Friday, February 10, 2017

Java - redirect standard output stream to file


Buy Moto series phones: Moto E, Moto G, Moto X or Other phones
Buy eBooks from Flipkart
-----------------------------------------------


 We can redirect all System.out.println output to a file with below code snippet.

 System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream("/tmp/output.txt"))));

Latest Posts