如何用shell实现有趣的功能(shell脚本实现一个简单功能)

本文目录
- shell脚本实现一个简单功能
- shell这个功能怎么实现呢
- 在linux中如何在代码中实现shell中实现的功能
- 如何用shell脚本实现下列功能
- 如何在shell实现类似sql%rowcount的功能
- linux下shell如何实现以下功能
- 编写一个Shell脚本文件list.sh,实现以下功能
shell脚本实现一个简单功能
晕,我被度娘整凌乱了,就上面这些内容,我一提交就提醒我“您的回答包含不适合发表的内容,请修改后提交”,我看半天不知道该修改哪儿,到底哪一句惹到度娘了?楼主凑合看吧。
shell这个功能怎么实现呢
判断输入参数main,你用命令自变量弄吧,例如$1代表的是第一个命令自变量。然后用case判断好了,
case “$1” in main)
main
;;
同理,你的fuction1和fuction2也可以用上面的方法实现运行一次,比如输入参数fuc1时也用case判断一次,就可以实现了吧?
貌似理解错了:别把function1和fuction2放到main里面。
2:以后要执行main就添加下列语句:
if
then
main
fi
在linux中如何在代码中实现shell中实现的功能
(1)建立一个目录 mkdir -p /var/run/fruinfo/
(2)新建并这个文件 /var/run/fruinfo/LCHAS
文件里面写入N,这个N每次都不同,可以在执行脚本时候定义,然后保存退出
(3)建立一个目录 mkdir -p /var/run/frus/
(4)新建这个文件 /var/run/frus/slot
文件里面写入X,这个X每次都不同,可以在执行脚本时候定义,然后保存退出
如何用shell脚本实现下列功能
楼上两个真经典, 受教受教. 我菜鸟冒昧解释解释两位的命令
cat log.txt| gawk -F’#| ’ ’{print $5}’|sort|uniq -c|gawk ’{print $2,$1}’
-F’#| ’ 利用#或者空格分隔, 第一次碰到学习了
sort 排序
uniq -c 合并重复, 统计个数
awk -F")}’ temp.log
太nb了, 佩服佩服awk用的如此之娴熟
-F"" 同样用#或者空格分隔, 学习学习
a(也就是1个或者多个z), 然后用内置函数length取出来数字内有多少个z就是重复了几次. 高!
厚颜无耻的补充一下排序加上sort就行了
awk -F") | "sort"}’ datafile
to 楼上
谦虚谦虚了
看了优化命令
awk -F"#| " ’{a}’ temp.log 1》aaa.txt
不错, 我又没有想到!!! 直接自增1 不用length统计了直接打印. 太棒了
如何在shell实现类似sql%rowcount的功能
1
最简单的shell里调用sqlplus.
$ vi test1.sh
#!/bin/bash
sqlplus -S /nolog 《《EOF
set heading off feedback off pagesize 0 verify off echo off
conn test/test
select * from tab;
exit
EOF
$ chmod +x test1.sh
$ ./test1.sh
2
把sqlplus执行结果传递给shell方法一
$ vi test2.sh
#!/bin/bash
VALUE=`sqlplus -S /nolog 《《EOF
set heading off feedback off pagesize 0 verify off echo off numwidth 4
conn test/test
select count(*) from tab;
exit
EOF`
if ; then
echo "The number of rows is $VALUE."
exit 0
else
echo "There is no row in the table."
fi
$ chmod +x test2.sh
$ ./test2.sh
3
把sqlplus执行结果传递给shell方法二
$ vi test3.sh
#!/bin/bash
sqlplus -S /nolog 《《EOF
set heading off feedback off pagesize 0 verify off echo off numwidth 4
conn test/test
col coun new_value v_coun
select count(*) coun from tab;
exit v_coun
EOF
VALUE="$?"
echo "The number of rows is $VALUE."
$ chmod +x test3.sh
$ ./test3.sh
4
把shell程序参数传递给sqlplus
$1表示第一个参数, sqlplus里可以直接使用, 赋变量的等号两侧不能有空格不能有空格.
$ vi test4.sh
#!/bin/bash
NAME="$1"
sqlplus -S test/test 《《EOF
select * from tab where tname = upper(’$NAME’);
exit
EOF
$ chmod +x test4.sh
$ ./test4.sh ttt
5
为了安全要求每次执行shell都手工输入密码
$ vi test5.sh
#!/bin/bash
echo -n "Enter password for u_test:"
read PASSWD
sqlplus -S /nolog 《《EOF
conn test/$PASSWD
select * from tab;
exit
EOF
$ chmod +x test5.sh
$ ./test5.sh
6
为了安全从文件读取密码
对密码文件设置权限, 只有用户自己才能读写.
$ echo ’test’ 》 u_test.txt
$ chmod g-rwx,o-rwx u_test.txt
$ vi test6.sh
#!/bin/bash
PASSWD=`cat u_test.txt`
sqlplus -S /nolog 《《EOF
conn test/$PASSWD
select * from tab;
exit
EOF
$ chmod +x test6.sh
$ ./test6.sh
linux下shell如何实现以下功能
Linux中增加软路由的两种方法
第一种:
route add -net 172.16.6.0 netmask 255.255.255.0 gw 172.16.2.254 dev eth0
/* 增加一条网络172.16.6.0/24 经过172.16.2.254 eth0 */
/* -net增加网络 -host增加主机 netmask 子网掩码 gw 网关 dev 装置,设备,这里是你的网卡名*/
route del gw 172.16.2.254 /* 删除默认网关172.16.2.254 */
route del -net 172.16.86.0/24 /* 删除默认网络172.16.86.0 */
route /* 显示当前路由表 */
常用的是这种方式,但有时你在删除或一条软路由时会不起作用,会有什么提示:
SIOCADDRT: 无法接触网路
所以这时用如下的这种方法就可以了
第二种:
实现的功能和上面的一样
ip route add 172.16.6.0/24 via 172.16.2.254 dev eth0
ip route del gw 172.16.2.254
ip route del 172.16.6.0/24 dev eth0
ip route
删除的方法:
添加路由:
route add -net 10.0.0.0 netmask 255.0.0.0 dev eth0
删除路由:
route del -net 10.0.0.0 netmask 255.0.0.0 dev eth0
添加默认路由:
route add default gw 10.0.0.1
删除默认路由:
route del default gw 10.0.0.1
或者
route del default
---------------------------------------------------------------------------------------
linux下添加路由的方法:
一:使用 route 命令添加
使用route 命令添加的路由,机器重启或者网卡重启后路由就失效了,方法:
//添加到主机的路由
# route add –host 192.168.168.110 dev eth0
# route add –host 192.168.168.119 gw 192.168.168.1
//添加到网络的路由
# route add –net IP netmask MASK eth0
# route add –net IP netmask MASK gw IP
# route add –net IP/24 eth1
//添加默认网关
# route add default gw IP
//删除路由
# route del –host 192.168.168.110 dev eth0
二:在linux下设置永久路由的方法:
1.在/etc/rc.local里添加
方法:
route add -net 192.168.3.0/24 dev eth0
route add -net 192.168.2.0/24 gw 192.168.3.254
2.在/etc/sysconfig/network里添加到末尾
方法:GATEWAY=gw-ip 或者 GATEWAY=gw-dev
3./etc/sysconfig/static-router :
any net x.x.x.x/24 gw y.y.y.y
编写一个Shell脚本文件list.sh,实现以下功能
#!/bin/bash
{
date
ls /etc/P*.conf
} 》 list.txt

更多文章:
avantage怎么设置为中文(Avantage安装丢失GIT)
2026年10月15日 03:00
activex控件未注册怎么办(登陆视频监控网页时提示activex控件未注册,怎么解决)
2026年10月14日 20:30
excel连接sql数据库教程(excel怎么连接sql数据库)
2026年10月14日 19:40






