Advertisement

包含365个shell高级编程实例。

  •  5星
  •     浏览量: 0
  •     大小:None
  •      文件类型:None


简介:
Shell脚本高级编程教程,旨在为您提供有益的指导。以下示例 10-23 阐述了在实际任务中利用 `continue N` 的应用: 1. 阿尔伯特·雷纳(Albert Reiner)提供了一个使用“continue N”的示例: 2. --------------------------------------------------------- 3. 假设我需要处理大量需要执行的任务,这些任务的数据存储在特定名称模式的文件中,这些文件位于一个指定的目录中。 多个机器同时访问这个目录,并且我希望将这些工作分配到不同的计算节点上。 因此,我通常会在每个节点上运行如下命令: 4. ```bash while true do for n in .iso\.* do if [ $n = .iso.opts ] then continue fi beta=${n#.iso.} if [ -r .Iso.$beta ] then continue fi if [ -r .lock.$beta ] then sleep 10 && continue fi lockfile -r0 .lock.$beta || continue echo -n $beta: `date` run-isotherm $beta date ls -alF .Iso.$beta if [ -r .Iso.$beta ] then rm -f .lock.$beta fi continue 2 done break 26 done # End of inner loop for processing files in directory. done # End of outer loop for continuous job execution. # The specific details, particularly the sleep duration, are tailored to my application; however, the fundamental pattern remains consistent: 5. ```bash 6. while true 7. do 8. for job in {pattern} 9. do 10. if {job already done or running} 11. then 12. continue 2 # Skip to the next job iteration if the current job is already in progress or completed. 13. fi # End of conditional check for existing jobs. 14. {mark job as running, do job, mark job as done} # Perform the necessary actions to execute the current job and update its status accordingly (e.g., start the process, execute the task). This section represents a placeholder for the actual job execution logic within this example script and should be replaced with appropriate commands or scripts to perform the desired tasks based on each `job`. This could involve executing another script, running a command-line tool, or performing any other action required by your specific use case.. Continue 2 # Skip to next iteration of outer loop after completing/skipping a particular Job.. 15. continue 2 # Skip to next iteration of outer loop after processing a particular Job.. 16. done # End of inner loop iterating through jobs based on defined pattern.. 17. break # Exit from inner loop when all jobs are processed or no more jobs are available.. 18.`sleep 600 to avoid termination.`# Optional sleep command added here for preventing premature script termination if no more jobs are available during runtime.. 19.`done`# End of outer while loop that continues until no more jobs are available.. 20.# This approach ensures that the script will only terminate when there are no remaining tasks to execute (including those added during runtime). Utilizing appropriate lockfiles enables concurrent execution across multiple machines without encountering duplication of calculations – a critical consideration given that my tasks can take several hours to complete, necessitating avoidance of redundant computations.. Furthermore, since searches always begin from the outset, priorities can be encoded within file names; alternatively, this functionality could be implemented without using `continue`, but it would necessitate explicit checks to determine whether a task was already completed before proceeding to search for subsequent tasks—potentially leading to either termination or prolonged waiting periods before checking for new jobs..

全部评论 (0)

还没有任何评论哟~
客服
客服
  • Shell精选(365
    优质
    《Shell高级编程案例精选(365例)》汇集了涵盖系统管理、自动化运维及脚本优化等方面的365个经典实例,旨在帮助读者掌握Shell脚本编程的深度与广度。 Shell脚本高级编程教程希望对你有所帮助。 示例10-23:使用continue N的实际任务: 阿尔伯特·莱纳尔提供了一个如何使用continue N的例子: 假设我有许多需要运行的任务,这些任务的数据文件遵循特定的命名模式,并位于一个目录中。有几台机器可以访问这个目录,我希望将工作分配到不同的机器上进行处理。通常在每台机器上nohup执行类似以下脚本: ``` while true do for n in .iso.* do [ $n = .iso.opts ] && continue beta=${n#.iso.} [ -r .Iso.$beta ] && continue [ -r .lock.$beta ] && sleep 10 && continue lockfile -r0 .lock.$beta || continue echo -n $beta: `date` run-isotherm $beta date ls -alF .Iso.$beta [ -r .Iso.$beta ] && rm -f .lock.$beta continue 2 done break done ``` 细节部分,特别是sleep N的部分,根据我的应用需求而定。但总体模式是: ``` while true do for job in {pattern} do {job already done or running} && continue {mark job as running, do job, mark job as done} continue 2 done break # 或者使用类似`sleep 600来避免终止。 done ``` 这样,脚本将仅在没有更多任务可执行时停止(包括运行期间添加的任务)。通过适当锁定文件的使用,可以在多台机器上并行运行而不会重复计算(在我的情况下这些计算会持续几个小时,所以我不想让它们被重复)。同时由于搜索总是从头开始进行,可以编码优先级到文件名中。当然也可以不使用`continue 2`,但那样的话就必须检查任务是否已完成(以便立即寻找下一个任务)或未完成(在这种情况下需要终止或者长时间睡眠后再检查新任务)。
  • Shell脚本100
    优质
    《Shell脚本编程实例100个》是一本全面介绍Linux Shell脚本编程技巧和应用的教程书,通过丰富的实例帮助读者掌握从基础到高级的各种脚本编写技术。 Shell脚本100例非常经典,涵盖了从简单到复杂的各种脚本,适合初学者参考学习,并且在企业实战中也能直接应用。
  • 100Shell脚本
    优质
    《100个Shell脚本编程实例》是一本详细讲解如何使用Shell脚本解决实际问题的手册,通过丰富的案例帮助读者提高自动化处理能力。 《Shell脚本编程100例》汇集了shell脚本的核心知识点,是一本全面的参考书。无论是学习、职业发展还是面试准备,这本书都是不可或缺的工具;同时它也非常适合日常使用和个人提升。
  • SHELL(中文清版).pdf
    优质
    《SHELL高级编程(中文高清版)》是一本深入讲解Shell脚本编程技术的专业书籍,适合已有基础的开发者阅读。书中内容清晰、示例丰富,帮助读者掌握复杂任务自动化技巧。 《SHELL高级编程》(中文高清版)涵盖了SED与AWK的深入学习以及基础内容。
  • Arduino版——50
    优质
    《Arduino高级版——包含50个实验》是一本深入探索Arduino编程和硬件应用的手册,通过丰富的实践项目帮助读者提升技术水平。 课程包含原理图和代码详解,带你一步步掌握Arduino的使用;实验内容包括:点亮LED、交通灯、激光头传感器检测、按键传感器检测、电容触摸检测、避障传感器检测、巡线传感器应用、光折断计数功能实现、倾斜模块工作原理讲解及碰撞传感器的工作原理介绍。课程还将涉及霍尔传感器和干簧管的使用,人体红外感应技术以及有源蜂鸣器播放声音的应用。此外还包括8002b功放模块的学习内容,130电机模块的操作方法,并详细介绍旋转电位器传感器、水滴与水蒸气检测装置及声音传感器测量声量的方法。 课程还涉及光敏电阻和NTC-MF52AT模拟温度传感器的使用技巧。薄膜压力传感器的应用也被涵盖在内,以及火焰监测技术的学习内容。此外,还包括MQ-2烟雾传感器和MQ-3酒精气体探测器的工作原理与应用实例讲解。摇杆模块的操作方法及太阳光紫外线感应装置的技术细节也在课程中有所涉及。 接下来是6812RGB模块的使用介绍、旋转编码器计数功能实现以及舵机控制技术的学习内容。超声波传感器的应用、红外遥控接收系统的设计方案也被包含在内,还有DS18B20温度传感器和DHT11温湿度检测模块的相关知识讲解。
  • LabVIEW详解
    优质
    《LabVIEW高级编程实例详解》一书深入浅出地讲解了LabVIEW编程语言的核心概念与高级技巧,并通过大量具体案例指导读者掌握实际应用技能。适合希望提升LabVIEW开发水平的技术人员阅读。 里面有很多LabVIEW的高级设计实例,非常不错。
  • 京峰教育的Linux Shell
    优质
    京峰教育的Linux Shell高级编程课程专为寻求深入掌握Shell脚本编写技巧的专业人士设计,涵盖高级编程概念与实践,助您成为Linux环境下的编程高手。 京峰教育的 Linux Shell 高级编程文档是内部私密资料(vip 内部文档),主要介绍在企业运维中的实战经验和关键技术点。 以下是本段落档的关键知识点概要: 1. **Shell 编程实践:系统备份脚本** 在日常的企业运营维护中,需要对重要的文件进行定期的备份操作。例如 /etc、/boot 分区和重要网站数据等。制定高效的备份策略至关重要,常见的方案包括: - 每周日进行全面的数据备份。 - 周一至周六采用增量方式补全未被覆盖的部分。 2. **使用 tar 工具进行系统数据的备份** `tar`工具是常用的文件打包和解包程序。通过此工具,可以实现网站的手动完整或增量备份。以下为示例代码: ``` tar -g /tmp/snapshot -czvf /tmp/2017_full_system_data.tar.gz /data/sh/ ``` 3. **Shell 脚本自动化打包和备份** 通过编写 Shell 脚本,可以自动完成数据的打包与备份任务。具体策略如下: * 按日期存放每日的备份文件。 * 定义完整备份及增量备份函数模块。 * 根据当前星期几来决定执行哪种类型的备份操作(完全或增量)。 示例代码片段展示如何通过脚本实现这一功能: ``` #!/bin/bash # 自动化Linux系统文件的备份 SOURCE_DIR=(*) TARGET_DIR=/data/backup YEAR=$(date +%Y) MONTH=$(date +%m) DAY=$(date +%d) WEEK=$(date +%u) A_NAME=$(date +%H%M) FILES=system_backup.tgz if [ -z $* ]; then echo 请指定需要备份的文件或目录 exit 1 fi ``` 4. **自动化运维实践** 文档还涵盖了构建自动化运维体系的相关内容,包括: * 收集服务器信息。 * 防止恶意 IP 访问网站。 * 实现 LAMP+MySQL 主从架构的部署与维护。 * 处理大规模服务器群中的IP地址更改问题。 * 自动化配置 Nginx 和 Tomcat,以及 Docker 管理平台等。 本段落档为 Linux 服务管理和自动化运维提供了宝贵的实战经验和技巧参考。
  • Excel工具箱:17插件
    优质
    Excel高级工具箱是一款集成了17种强大功能插件的高效办公软件扩展程序,适用于需要处理大量复杂数据和报表的职场精英。 Excel高级工具箱包含17个高级插件集合。
  • VC++6.0100及源代码)
    优质
    《VC++6.0实用编程百例》一书收录了100个经典实例及其完整源代码,涵盖Windows应用程序开发的核心技术与技巧。适合初学者和中级程序员学习实践。 通过100个VC编程实例(如带图标的菜单、显示倾斜文字)来更快地掌握编写VC程序的方法。