自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Unix自動化問題講解

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

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

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

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

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

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

清單 4:用簡單的腳本調用 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自動化的一個問題,我們就講解到這里了。

【編輯推薦】

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

2010-05-04 11:59:39

Unix系統(tǒng)

2010-05-04 14:54:32

Unix網(wǎng)關

2021-02-01 11:03:36

Python開發(fā)郵件

2010-05-06 17:07:34

Unix命令

2017-12-17 21:58:18

2024-11-01 15:05:12

2010-05-07 17:21:55

Unix系統(tǒng)

2010-05-07 17:26:32

Unix系統(tǒng)

2010-04-15 18:06:08

Unix操作系統(tǒng)

2018-07-13 06:46:35

數(shù)據(jù)中心自動化微服務

2011-07-25 14:53:37

Unix服務器運維

2010-04-21 15:20:31

Unix線程

2010-05-05 13:13:55

Unix內核

2010-05-05 17:30:04

Unix MBB

2018-02-25 19:29:49

自動化數(shù)字化IT

2022-02-18 13:12:49

人工智能自動化技術

2021-10-13 10:06:49

自動化IT安全

2010-12-06 09:59:58

2022-02-04 21:50:37

網(wǎng)絡安全自動化

2020-04-29 11:28:54

智能自動化機器人流程自動化AI
點贊
收藏

51CTO技術棧公眾號