偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Unix自動(dòng)化問題講解

系統(tǒng) 其他OS 自動(dòng)化
利用 cfengine,可以根據(jù)任意標(biāo)準(zhǔn)Unix自動(dòng)化幾乎任何任務(wù)。但是,它的功能非常象 Makefile 功能,對變量的復(fù)雜操作是很難處理的。

我們在使用Unix的時(shí)候,經(jīng)常需要運(yùn)用到Unix自動(dòng)化的知識(shí)。今天,我們就來了解下Unix自動(dòng)化的知識(shí)。任務(wù)自動(dòng)化是一個(gè)很泛的主題。我將本節(jié)僅限于非交互式 簡單自動(dòng)化。對于交互式命令的Unix自動(dòng)化,Expect 是當(dāng)前可用的***工具。應(yīng)該要么了解它的語法,要么用 Perl Expect.pm 模塊??梢詮?CPAN 獲取 Expect.pm;請參閱參考資料以了解更多詳細(xì)信息。

利用 cfengine,可以根據(jù)任意標(biāo)準(zhǔn)Unix自動(dòng)化幾乎任何任務(wù)。但是,它的功能非常象 Makefile 功能,對變量的復(fù)雜操作是很難處理的。

當(dāng)發(fā)現(xiàn)需要運(yùn)行這樣的命令,該命令的參數(shù)來自于散列或通過單獨(dú)的函數(shù)時(shí),通常***切換到 shell 腳本或 Perl。由于 Perl 的功能,其可能是較好的選擇。雖然,不應(yīng)該將 shell 腳本棄為替代來使用。有時(shí),Perl 是不必要的,您只需要運(yùn)行一些簡單的命令。

Unix自動(dòng)化中,自動(dòng)添加用戶是一個(gè)常見問題??梢跃帉懽约旱?adduser.pl 腳本,或者用大多數(shù)現(xiàn)代 Unix 系統(tǒng)提供的 adduser 程序。請確保使用的所有 Unix 系統(tǒng)間語法是一致的,但不要嘗試編寫一個(gè)通用的 adduser 程序接口。

它太難了,在您認(rèn)為涵蓋了所有 Unix 變體后,遲早會(huì)有人要求 Win32 或 MacOS 版本。這不是僅僅用 Perl 就能解決的問題之一,除非您是非常有野心的。這里只是讓腳本詢問用戶名、密碼、主目錄等等,并以 system() 調(diào)用來調(diào)用 adduser。

清單 4:用簡單的腳本調(diào)用 adduser
 

  1. #!/usr/bin/perl -w   
  2. use strict;   
  3. my %values; # will hold the values to fill in   
  4. # these are the known adduser switches   
  5. my %switches = ( home_dir => '-d', comment => '-c', group => '-G',   
  6. password => '-p', shell => '-s', uid => '-u');   
  7. # this location may vary on your system   
  8. my $command = '/usr/sbin/adduser ';   
  9. # for every switch, ask the user for a value   
  10. foreach my $setting (sort keys %switches, 'username')   
  11. {   
  12. print "Enter the $setting or press Enter to skip: ";   
  13. $values{$setting} = ;   
  14. chomp $values{$setting};   
  15. # if the user did not enter data, kill this setting   
  16. delete $values{$setting} unless length $values{$setting};   
  17. }   
  18. die "Username must be provided" unless exists $values{username};   
  19. # for every filled-in value, add it with the right switch to the comma  
  20. nd   
  21. foreach my $setting (sort keys %switches)   
  22. {   
  23. next unless exists $values{$setting};   
  24. $command ."$switches{$setting} $values{$setting} ";   
  25. }   
  26. # append the username itself   
  27. $command .= $values{username};   
  28. # important - let the user know what's going to happen   
  29. print "About to execute [$command]\n";   
  30. # return the exit status of the command   
  31. exit system($command);  

Unix自動(dòng)化的一個(gè)問題,我們就講解到這里了。

【編輯推薦】

  1. Unix系統(tǒng)中知識(shí)講解
  2. Unix cpio命令詳細(xì)解析
  3. AIX CDE的問題解決講解
  4. Unix系統(tǒng)與小型機(jī)的討論
  5. Unix Telnet知識(shí)講解
責(zé)任編輯:小霞
相關(guān)推薦

2010-05-04 11:59:39

Unix系統(tǒng)

2010-05-04 14:54:32

Unix網(wǎng)關(guān)

2021-02-01 11:03:36

Python開發(fā)郵件

2010-05-06 17:07:34

Unix命令

2010-05-07 17:26:32

Unix系統(tǒng)

2010-05-07 17:21:55

Unix系統(tǒng)

2017-12-17 21:58:18

2024-11-01 15:05:12

2010-04-15 18:06:08

Unix操作系統(tǒng)

2011-07-25 14:53:37

Unix服務(wù)器運(yùn)維

2018-07-13 06:46:35

數(shù)據(jù)中心自動(dòng)化微服務(wù)

2010-04-21 15:20:31

Unix線程

2010-05-05 17:30:04

Unix MBB

2010-05-05 13:13:55

Unix內(nèi)核

2010-04-30 13:27:26

Unix cronta

2010-05-04 12:25:28

Unix鏈接

2010-05-05 13:45:21

Unix Telnet

2010-05-05 16:05:36

Unix cfengi

2010-05-05 17:41:03

IBM Unix

2010-05-04 09:22:10

Unix文件
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)