LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 822|回复: 4

[求助]怎样编写shell脚本

[复制链接]
发表于 2005-6-24 02:56:43 | 显示全部楼层 |阅读模式
我是一个初学者,想用vi编写一个shell脚本。
shell脚本的扩展名是什么?
我想开机就运行这个shell脚本,应该放在哪个目录下
希望大家帮帮我
发表于 2005-6-24 06:32:29 | 显示全部楼层
Post by zhouyu2004
我是一个初学者,想用vi编写一个shell脚本。
shell脚本的扩展名是什么?
我想开机就运行这个shell脚本,应该放在哪个目录下
希望大家帮帮我


1。其实shell脚本可以没有什么扩展名,有些时候为了于binary分开,也有加.sh的。
2。要具体看你使用的是什么发行版的。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-6-24 10:22:42 | 显示全部楼层
我用redhat
我想把下列内容编写脚本:
#!/bin/bash

# Uncomment this section if you have physical cds and want to convert them to
# ISOs first. You need to have the ISOs, named as in this script, for this
# script to work predictably.
#------------------------------------------------------------------------------
#echo Please insert disk 1 of 5 and hit any key to continue.
#read key
#dd if=/dev/cdrom of=SUSE-9.3-Prof-i386-CD1.iso
#echo Please insert disk 2 of 5 and hit any key to continue.
#read key
#dd if=/dev/cdrom of=SUSE-9.3-Prof-i386-CD2.iso
#echo Please insert disk 3 of 5 and hit any key to continue.
#read key
#dd if=/dev/cdrom of=SUSE-9.3-Prof-i386-CD3.iso
#echo Please insert disk 4 of 5 and hit any key to continue.
#read key
#dd if=/dev/cdrom of=SUSE-9.3-Prof-i386-CD4.iso
#echo Please insert disk 5 of 5 and hit any key to continue.
#read key
#dd if=/dev/cdrom of=SUSE-9.3-Prof-i386-CD5.iso
#------------------------------------------------------------------------------


#Mount the CDs in loopback mode:
mkdir CD1 CD2 CD3 CD4 CD5

mount SUSE-9.3-Prof-i386-CD1.iso CD1 -o loop
mount SUSE-9.3-Prof-i386-CD2.iso CD2 -o loop
mount SUSE-9.3-Prof-i386-CD3.iso CD3 -o loop
mount SUSE-9.3-Prof-i386-CD4.iso CD4 -o loop
mount SUSE-9.3-Prof-i386-CD5.iso CD5 -o loop

# Create a basic structure to overwrite files we need to modify for the CD (the checksums and boot files).
cp -a CD1/boot .
mkdir i586 i686 noarch

# Create the NEW MD5SUMS as one file in order to allow SuSE to validate (thus install) all of the files from every CD and not just CD #1
# For the i586 directory:
cat CD1/suse/i586/MD5SUMS CD2/suse/i586/MD5SUMS CD3/suse/i586/MD5SUMS CD4/suse/i586/MD5SUMS CD5/suse/i586/MD5SUMS > i586/MD5SUMS
# For the i686 directory:
cat CD1/suse/i686/MD5SUMS CD2/suse/i686/MD5SUMS > i686/MD5SUMS
# For the noarch directory:
cat CD1/suse/noarch/MD5SUMS CD2/suse/noarch/MD5SUMS CD3/suse/noarch/MD5SUMS CD4/suse/noarch/MD5SUMS CD5/suse/noarch/MD5SUMS > noarch/MD5SUMS

# Now, create the ISO:
mkisofs -o SuSE_9.3.iso -b boot/loader/isolinux.bin -c boot/loader/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -l -P SuSE -r -T -V SuSE_9.3 -x CD1/boot -x CD1/suse/i586/MD5SUMS -x CD1/suse/noarch/MD5SUMS -x CD1/suse/i686/MD5SUMS -x CD2/suse/i686/MD5SUMS -x CD2/suse/i586/MD5SUMS -x CD2/suse/noarch/MD5SUMS -x CD3/suse/i586/MD5SUMS -x CD3/suse/noarch/MD5SUMS -x CD4/suse/i586/MD5SUMS -x CD4/suse/noarch/MD5SUMS -x CD5/suse/i586/MD5SUMS -x CD5/suse/noarch/MD5SUMS -graft-points CD1 boot/=boot suse/i586/MD5SUMS=i586/MD5SUMS suse/noarch/MD5SUMS=noarch/MD5SUMS suse/i686/MD5SUMS=i686/MD5SUMS suse/=CD2/suse suse/=CD3/suse suse/=CD4/suse suse/=CD5/suse media.2/=CD2/media.2 media.3/=CD3/media.3 media.4/=CD4/media.4 media.5/=CD5/media.5

# Now just burn the ISO to a DVD (hint: use 'growisofs' or your favorite GUI-frontend to 'growisofs'). Optionally, you can mount this ISO like you did #above to verify it will work correctly, or if you don't want to actually burn it. Just call:
#mkdir DVD
#mount SuSE_9.3.iso DVD -o loop

# Enjoy!
回复 支持 反对

使用道具 举报

发表于 2005-6-24 13:41:48 | 显示全部楼层
Post by zhouyu2004
我用redhat
我想把下列内容编写脚本:
#!/bin/bash

# Uncomment this section if you have physical cds and want to convert them to
# ISOs first. You need to have the ISOs, named as in this script, for this
# script to work predictably.
#------------------------------------------------------------------------------
#echo Please insert disk 1 of 5 and hit any key to continue.
#read key
#dd if=/dev/cdrom of=SUSE-9.3-Prof-i386-CD1.iso
#echo Please insert disk 2 of 5 and hit any key to continue.
#read key
#dd if=/dev/cdrom of=SUSE-9.3-Prof-i386-CD2.iso
#echo Please insert disk 3 of 5 and hit any key to continue.
#read key
#dd if=/dev/cdrom of=SUSE-9.3-Prof-i386-CD3.iso
#echo Please insert disk 4 of 5 and hit any key to continue.
#read key
#dd if=/dev/cdrom of=SUSE-9.3-Prof-i386-CD4.iso
#echo Please insert disk 5 of 5 and hit any key to continue.
#read key
#dd if=/dev/cdrom of=SUSE-9.3-Prof-i386-CD5.iso
#------------------------------------------------------------------------------


#Mount the CDs in loopback mode:
mkdir CD1 CD2 CD3 CD4 CD5

mount SUSE-9.3-Prof-i386-CD1.iso CD1 -o loop
mount SUSE-9.3-Prof-i386-CD2.iso CD2 -o loop
mount SUSE-9.3-Prof-i386-CD3.iso CD3 -o loop
mount SUSE-9.3-Prof-i386-CD4.iso CD4 -o loop
mount SUSE-9.3-Prof-i386-CD5.iso CD5 -o loop

# Create a basic structure to overwrite files we need to modify for the CD (the checksums and boot files).
cp -a CD1/boot .
mkdir i586 i686 noarch

# Create the NEW MD5SUMS as one file in order to allow SuSE to validate (thus install) all of the files from every CD and not just CD #1
# For the i586 directory:
cat CD1/suse/i586/MD5SUMS CD2/suse/i586/MD5SUMS CD3/suse/i586/MD5SUMS CD4/suse/i586/MD5SUMS CD5/suse/i586/MD5SUMS > i586/MD5SUMS
# For the i686 directory:
cat CD1/suse/i686/MD5SUMS CD2/suse/i686/MD5SUMS > i686/MD5SUMS
# For the noarch directory:
cat CD1/suse/noarch/MD5SUMS CD2/suse/noarch/MD5SUMS CD3/suse/noarch/MD5SUMS CD4/suse/noarch/MD5SUMS CD5/suse/noarch/MD5SUMS > noarch/MD5SUMS

# Now, create the ISO:
mkisofs -o SuSE_9.3.iso -b boot/loader/isolinux.bin -c boot/loader/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -l -P SuSE -r -T -V SuSE_9.3 -x CD1/boot -x CD1/suse/i586/MD5SUMS -x CD1/suse/noarch/MD5SUMS -x CD1/suse/i686/MD5SUMS -x CD2/suse/i686/MD5SUMS -x CD2/suse/i586/MD5SUMS -x CD2/suse/noarch/MD5SUMS -x CD3/suse/i586/MD5SUMS -x CD3/suse/noarch/MD5SUMS -x CD4/suse/i586/MD5SUMS -x CD4/suse/noarch/MD5SUMS -x CD5/suse/i586/MD5SUMS -x CD5/suse/noarch/MD5SUMS -graft-points CD1 boot/=boot suse/i586/MD5SUMS=i586/MD5SUMS suse/noarch/MD5SUMS=noarch/MD5SUMS suse/i686/MD5SUMS=i686/MD5SUMS suse/=CD2/suse suse/=CD3/suse suse/=CD4/suse suse/=CD5/suse media.2/=CD2/media.2 media.3/=CD3/media.3 media.4/=CD4/media.4 media.5/=CD5/media.5

# Now just burn the ISO to a DVD (hint: use 'growisofs' or your favorite GUI-frontend to 'growisofs'). Optionally, you can mount this ISO like you did #above to verify it will work correctly, or if you don't want to actually burn it. Just call:
#mkdir DVD
#mount SuSE_9.3.iso DVD -o loop

# Enjoy!

先看看书或者在论坛里看看先.
回复 支持 反对

使用道具 举报

发表于 2005-6-24 13:48:01 | 显示全部楼层
这不是suse,5cd变一个dvd的脚本马?
这个就是脚本,可以执行,但是要根据你的系统调整内容
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表