Note that there are some explanatory texts on larger screens.

plurals
  1. POcopying logs in python using the command line function
    text
    copied!<p>I had a doubt with my code which i think I can verify here . My requirement is to copy the apache log and error log from two different servers . Iv written down a python program, using a for loop. </p> <p>My code: </p> <pre class="lang-python prettyprint-override"><code>def copylogs(Appache,Errorlog, folder_prefix) : root_path = '/home/tza/Desktop/LOGS/' folders = ['Appache','Errorlog'] for folder in folders: folder_name = folder_prefix + "_" + folder + str(int(time.time())) mkdircmd = "mkdir -p " + root_path + "/" + folder_name os.system(mkdircmd) filePath = root_path + folder_name serverPath = "/var/log/apache/*" cmd = "scp " + "symentic@60.62.1.164:" + serverPath + " " + filePath cmd = cmd.replace("60.62.1.164" ,myip1) cmd = os.system(cmd) print "Logs are at:",root_path+folder_name time.sleep(10) filePath = root_path + folder serverPath = "/var/log/errorlog/*" cmd = "scp " + "symentic@10.95.21.129:" + serverPath + " " + filePath cmd = cmd.replace("10.95.21.129" ,myip2) cmd = os.system(cmd) print "Logs are at:",root_path+folder_name </code></pre> <p>now Im calling the function at the end of my program :</p> <pre><code>folder_prefix = "Fail Case-1" copylogs(Appache,Errorlog, folder_prefix) </code></pre> <p>I have an issue here . Programm executes successfully but the logs get overwritten .what i mean is first Appache folder gets created ,logs are copied and then once again it gets overwritten .</p> <p>What i require is : create a folder Appachelogs[with the timestamp as defined ] ,copy the logs from machine one , next copy error logs from machine2 , and continue the program </p> <p>How can this be achieved? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload