Linux 读取txt文件并将值解析为bash脚本
我有以下bash脚本:Linux 读取txt文件并将值解析为bash脚本,linux,bash,variables,loops,while-loop,Linux,Bash,Variables,Loops,While Loop,我有以下bash脚本: #!/bin/bash filename='config.txt' while filename = read -r line do for file in $(find /home/user/ftpuser -maxdepth 1 -name "*.[ew]ar" -type f); do /apps/oracle/jrockit/4.1.0-1.6.0_37-R28.2.5-x86_64/bin/java -jar ../windu
#!/bin/bash
filename='config.txt'
while filename = read -r line do
for file in $(find /home/user/ftpuser -maxdepth 1 -name "*.[ew]ar" -type f); do
/apps/oracle/jrockit/4.1.0-1.6.0_37-R28.2.5-x86_64/bin/java -jar ../windup-cli-0.6.8/windup-cli.jar -javaPkgs com.lib - input ../ftpuser/ -output ../reports/ "${file}"
cp "${file}" /home/user/ftpuser/scanned/
done < "$filename"
sleep 60
done
以下内容将为您提供需要报告的软件包列表:
grep "^packages" config.txt | cut -d= -f2 | tr ',' ' '
基于此,可以循环列表中的值:
filename="config.txt"
for i in $(grep "^packages" $filename | cut -d= -f2 | tr ',' ' '); do
for file in $(find /home/user/ftpuser -maxdepth 1 -name "*.[ew]ar" -type f); do
echo /apps/oracle/jrockit/4.1.0-1.6.0_37-R28.2.5-x86_64/bin/java -jar ../windup-cli-0.6.8/windup-cli.jar -javaPkgs ${i} - input ../ftpuser/ -output ../reports/ "${file}"
cp "${file}" /home/user/ftpuser/scanned/
done
done
这就是我看到您可以如何使用它的方式:
#!/bin/bash
config_file='./config.txt' ## If you want to pass your configuration as an argument, use config_file=$1
. "$config_file"
while read -r file do
/apps/oracle/jrockit/4.1.0-1.6.0_37-R28.2.5-x86_64/bin/java -jar ../windup-cli-0.6.8/windup-cli.jar -javaPkgs com.lib - input ../ftpuser/ -output ../reports/ "${file}"
cp "${file}" /home/user/ftpuser/scanned/
sleep 60
done < <(exec find /home/user/ftpuser -maxdepth 1 -name '*.[ew]ar' -type f)
#/bin/bash
config_file='./config.txt'##如果要将配置作为参数传递,请使用config_file=$1
. “$config_文件”
而read-r文件呢
/apps/oracle/jrockit/4.1.0-1.6.0_37-R28.2.5-x86_64/bin/java-jar../windup-cli-0.6.8/windup-cli.jar-javaPkgs com.lib-input../ftpuser/-output../reports/“${file}”
cp“${file}”/home/user/ftpuser/scanned/
睡60
完成<文件名=read-r line do
--这应该做什么?我希望这会读取config.txt,但它不会。您可以将文件作为bash脚本读取,从中获取变量,如源代码“config.txt”
,然后如查找$path…
,如果您想这样做的话?部分是的。我会尽量说得更清楚。在config.txt文件中,您可以看到所有这些值。targetHostName,packages e.t.c.我需要做的是编写一个脚本,它从config.txt读取值,然后执行我前面提到的过程。我会检查它并让您知道!
#!/bin/bash
config_file='./config.txt' ## If you want to pass your configuration as an argument, use config_file=$1
. "$config_file"
while read -r file do
/apps/oracle/jrockit/4.1.0-1.6.0_37-R28.2.5-x86_64/bin/java -jar ../windup-cli-0.6.8/windup-cli.jar -javaPkgs com.lib - input ../ftpuser/ -output ../reports/ "${file}"
cp "${file}" /home/user/ftpuser/scanned/
sleep 60
done < <(exec find /home/user/ftpuser -maxdepth 1 -name '*.[ew]ar' -type f)