In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This paper mainly studies the related contents of the batch execution program that uses Python to generate Shell commands in Linux system, as follows.
These days it is common to encounter batch execution of similar commands in Linux shell. For example, execute the following command:
Gifsicle-- delay=100 gif/App_1_hour_*_down.gif > combine_gif/App_1_hour_down.gif gifsicle-- delay=100 gif/App_1_hour_*_up.gif > combine_gif/App_1_hour_up.gif gifsicle-- delay=100 gif/App_2_hour_*_down.gif > combine_gif/App_2_hour_down.gif gifsicle-- delay=100 gif/App_2_hour_*_up.gif > combine_gif/App_2_hour _ up.gif gifsicle-- delay=100 gif/App_3_hour_*_down.gif > combine_gif/App_3_hour_down.gif gifsicle-- delay=100 gif/App_3_hour_*_up.gif > combine_gif/App_3_hour_up.gif gifsicle-- delay=100 gif/App_4_hour_*_down.gif > combine_gif/App_4_hour_down.gif gifsicle-- delay=100 gif/App_4_hour_*_up.gif > combine_gif/App _ 4_hour_up.gif gifsicle-- delay=100 gif/App_5_hour_*_down.gif > combine_gif/App_5_hour_down.gif
If you enter manually, the error rate is high, the time cost is high, and the efficiency is very low. It is easy to batch process the above programs using Shell programming, but it can also be easily implemented if you are not familiar with Shell programming. The key is the change of thinking. We can use Python to write the above command to a file, and then copy the contents of the file into the .sh file at the beginning of #! / bin/bash to build the required Shell script file. The Python code that generates the above command is as follows:
Output = open ("C:\\ Python34\\ shell_commands.txt", "w") for i in range (1 21): wr_line_1 = "gifsicle-- delay=100 gif/App_" + str (I) + "_ hour_*_down.gif > combine_gif/App_" + str (I) + "_ hour_down.gif" + "\ n" wr_line_2 = "gifsicle-- delay=100 gif/App_" + str (I) + "_ hour_*_up.gif > combine_gif/App_" + str (I) + "_ hour_up.gif" + "\ n "output.writelines (wr_line_1) output.writelines (wr_line_2) output.close ()
Summary
This is the whole content of this article about using Python to generate Shell commands and batch execute program code parsing. I hope it will be helpful to you. Interested friends can continue to refer to other related topics on this site, if there are any deficiencies, please leave a message to point out. Thank you for your support to this site!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.