+ -
当前位置:首页 → 问答吧 → 不同输出结果如何取相同的变量值?

不同输出结果如何取相同的变量值?

时间:2011-01-31

来源:互联网

有如下执行结果,有2种情况,但俺想将Primary主版本赋值给变量1,将Secondary 版本赋值给变量2,  $1取到 v6.0.1a 或v5.2.3 ;
$2取到 v5.3.2a或v5.2.3 该如何实现?

swd77:admin> firmwareshow

Appl     Primary/Secondary Versions

------------------------------------------

FOS      v6.0.1a

         v5.3.2a



swd77:admin> firmwareshow

Primary version:         v5.2.3

Secondary version:         v5.2.3

作者: chinaboywg   发布时间: 2011-01-31

:em27:  没人顶 自己先顶起

作者: chinaboywg   发布时间: 2011-01-31

本帖最后由 chinaboywg 于 2011-01-31 13:00 编辑

要求2个结果套用一个表达式

作者: chinaboywg   发布时间: 2011-01-31

var1=`ur_cmd | awk 'NF{v=s;s=$NF}END{print v}'`
var2=`ur_cmd | awk 'NF{s=$NF}END{print s}'`

作者: ywlscpl   发布时间: 2011-01-31

本帖最后由 yinyuemi 于 2011-01-31 13:45 编辑

回复 chinaboywg


    var1=`command|awk '{if(/FOS/){print $NF}else{if(/Primary/){print $NF}}}'`
    var2=`command|awk '/FOS/{next}/Secondary/{next}END{print $NF}'`

作者: yinyuemi   发布时间: 2011-01-31

:em27::em30:  谢谢啊

作者: chinaboywg   发布时间: 2011-01-31

还有个是这样的如何实现呢

swd77:admin> firmwaredownload

Server Name or IP Address: 172.16.16.16

User Name: root

File Name: ./v6.2.2b/release.plist

Network Protocol(1-auto-select, 2-FTP, 3-SCP) [1]: 2

Password:

Checking system settings for firmwaredownload...

Server IP: 172.16.16.16, Protocol IPv4

System settings check passed.



You can run firmwaredownloadstatus to get the status

of this command.



This command will cause a warm/non-disruptive boot on the switch,

but will require that existing telnet, secure telnet or SSH sessions

be restarted.





Do you want to continue [Y]: y

Firmware is being downloaded to the switch. This step may take up to 30 minutes.

Preparing for firmwaredownload...

Removing fabos-drivers

Start to install packages...




swd77:admin> firmwaredownload

Server Name or IP Address: 172.16.16.16

FTP User Name: root

File Name: ./v5.3.2a/release.plist

FTP Password:

Verifying the input parameters ...

Checking system settings for firmwaredownload...

You can run firmwaredownloadstatus to get the status

of this command.



This command will cause a warm/non-disruptive boot on the switch,

but will require that existing telnet, secure telnet or SSH sessions

be restarted.



Do you want to continue [Y]: y

Firmware is being downloaded to the switch. This step may take up to 30 minutes.

Preparing for firmwaredownload...

Removing wget-1.5.3-1

Removing ftp-0.17-1

Removing lkcd-4.1_1_2.4.19-1

Removing ncftp-3.0.3-3

Removing binutils-libs-2.10.1-1

Removing fabos-fw-5.2.3-8

Removing binutils-2.10.1-1

Removing mmlib-1.1.3-1

Removing fabos-diagdev-5.2.3-10

Start to install packages...



区别就是一个有2,一个没有2
而且还要用expect实现,如何弄?

作者: chinaboywg   发布时间: 2011-01-31