shell脚本来执行的nohup针对inputed文件名 [英] Shell script to execute nohup against an inputed filename

查看:145
本文介绍了shell脚本来执行的nohup针对inputed文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断地运行命令,像

  nohup的PSQL -d分贝-f foo1.sql>&安培; foo1.out&安培;
nohup的PSQL -d分贝-f foo2.sql>&安培; foo2.out&安培;

我想知道如何创建一个shellscript里是作为输入文件名参数一样foo1.sql并运行上面的命令。

我怎样写一个叫做测试脚本,因此命令 ./测试foo1.sql 将执行命令

  nohup的PSQL -d分贝-f foo1.sql>&安培; foo1.out&安培;


解决方案

试试这个

 #!/斌/庆典OUTPUTFILE =$(回声$ 1 |切-d \\ -f 1)的.outnohup的PSQL -d分贝-f$ 1>&安培; $ OUTPUTFILE与&

这不是与 ./测试(foo1.sql)名为,但 ./测试foo1.sql ,如这个问题被编辑后显示。

I am constantly running commands like

nohup psql -d db -f foo1.sql >& foo1.out &
nohup psql -d db -f foo2.sql >& foo2.out &

I was wondering how to create a shellscript that takes as input the filename parameter like foo1.sql and runs the command above.

How do I write a script called test so that the command ./test foo1.sql will execute the command

nohup psql -d db -f foo1.sql >& foo1.out &

解决方案

Try this

#!/bin/bash

outputFile="$(echo $1 | cut -d\. -f 1).out"

nohup psql -d db -f "$1" >& "$outputFile" &

It's not called with ./test(foo1.sql) but ./test foo1.sql, as shown after the question was edited.

这篇关于shell脚本来执行的nohup针对inputed文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆