当前位置:首页 » 网页前端 » shell执行目录下所有脚本
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

shell执行目录下所有脚本

发布时间: 2022-01-23 17:37:23

Ⅰ shell批量执行多个shell脚本

把多个shell脚本的执行命令和必要的参数,分行写入一个脚本文件中,加上日志输出。

Ⅱ shell脚本实现统计目录下(包括子目录)所有文件的个数

在shell终端中输入下列命令:

#在当前目录生成脚本文件countfile
cat>countfile<<SCRIPT
#!/bin/sh
find"$@"-typef|
wc-l
SCRIPT
#为脚本添加权限
chmod+xcountfile
#执行用例
./countfile~

Ⅲ shell批量执行不同目录下的多个sh文件的写法

按照你的说法,需要首先遍历你需要的文件,然后用一个for循环来执行
遍历的话还需要知道你的脚本文件有什么通用的地方,比如都叫elasticsearch

那还是通过find来找
find . -type f -name elasticsearch*

Ⅳ 如何运行文件夹中的所有shell脚本

foriin*.sh;dobash$i;done;

Ⅳ linux shell脚本怎么获取目录下所有txt文件名称

执行如下三条命令即可:
(1)、$script myresultfile
(2)、$ls -al *.txt
(3)、$exit

此时,该目录下的所有 txt 文件名称就会以长格式保存在 myresultfile 文件中了。

然后你再使用 SHELL 编程的功能把那些无用的列去掉即可。

Ⅵ 如何用shell脚本统计出当前目录下子目录,还有所有可读,可写,可执行的文件的个数

#!/bin/bash

fcnt=0
dcnt=0
frcnt=0
fwcnt=0
fxcnt=0
forfilein*
do
if[-f$file];then
letfcnt+=1
if[-r$file];then
letfrcnt+=1
fi
if[-w$file];then
letfwcnt+=1
fi
if[-x$file];then
letfxcnt+=1
fi
elif[-d$file];then
letdcnt+=1
fi
done
echo"Thereare$fcntfilesin$PWD"
echo-e" Thereare$frcntreadablefilesin$PWD"
echo-e" Thereare$fwcntwriteablefilesin$PWD"
echo-e" Thereare$fxcntexecuteablefilesin$PWD"
echo"Thereare$dcntdirectoriesin$PWD"

Ⅶ 如何用shell编程打印出目录下的所有文件内容

1)看下面的脚本a1.sh,假设要显示目录/home/user/tmp/下面的所有的文件和(子)目录的名字:

$ cat a1.sh
#!/bin/bash

for file in /home/user/tmp/*
do
echo $file
done

2)假设目录/home/user/tmp/下面的所有的文件和(子)目录如下:

$ ls
1.txt 2.txt a1.sh a.sh b.sh email_back m1.doc tmp

3)运行脚本:
$ a1.sh (或者./a1.sh)
/home/user/tmp/1.txt
/home/user/tmp/2.txt
/home/user/tmp/a1.sh
/home/user/tmp/a.sh
/home/user/tmp/b.sh
/home/user/tmp/email_back
/home/user/tmp/m1.doc
/home/user/tmp/tmp

4)脚本a1.sh的作用只是显示文件和子目录的列表,要显示文件的内容,脚本继续改造,内容如下,看脚本a2.sh:

$ cat a2.sh
#!/bin/bash

for file in /home/shiqingd/tmp/*
do
echo $file
if [ -f $file ]; then
cat $file
fi
done

脚本a2.sh可以达到目的。

Ⅷ 如何目录A下执行另一目录(目录B)下的shell脚本test

可能知道怎么回事了。

估计B脚本中添加了引用路径的当前变量。


比如:B脚本中有一变量

Cur_Dir=$(pwd)

这样执行过程如果不是当前目录执行的,就会引用A目录下的路径,自然找不到指定的文件。


知道原因后,即可在B下执行,或者变量B中的路径为完整路径

Ⅸ bash脚本遍历目录指定后缀的文件,并执行操作

可以使用ls或者find来完成对某个文件夹下所有文件的遍历
比如使用ls
可以简单地使用一个通配符来完成
ls 某个目录/*
也可以使用find来完成
比如
find 某个目录
自然的也可以写一个shell脚本来进行遍历
首先进行一个要遍历的文件夹
然后循环查看每个文件
如果该文件是一个文件夹的话则进入该文件夹做和上面相同的事件
这样就可以该整个文件夹内的所有文件进行遍历了
一个简单的代码如下
#!/bin/bash

function show()
{
cd $1

for i in `ls`
do
if [ -d "$i" ]
then
show "$i"
else
echo "$i"
fi
done

cd ..
}

show $1

exit 0
该程序不能遍历以.开头的隐藏文件
可以使用ls -a来进行遍历隐藏文件
遍历时需要注意.和..这两个特殊文件

下面是一个简单的代码
#!/bin/bash

function show()
{
cd $1

for i in `ls -a`
do
if [ "$i" == "." ] || [ "$i" == ".." ]
then
continue;
fi

if [ -d "$i" ]
then
show "$i"
else
echo "$i"
fi
done

cd ..
}

show $1

exit 0

Ⅹ shell批量执行同一目录不同文件夹里面的东西

注意文件本身别放到50个文件夹里面,容易造成死循环。
#!/bin/sh
for file in `find /opt -type f -name "*.sh"`;do
echo $file
sh $file
done