二月 6th, 2010 | 生活小札 | No Comments »
自从上次存储上面发现一个异常后,禁用不带密码的key。
而且关掉了sudo的nopasswd选项,
这下苦了我们自己,面对成百上千的服务器,需要拷贝个文件啊
或者root权限做个事情啊,那绝对是恶梦。为了拯救自己于恶梦,
利用NET::SSH,写了两个小脚本:
- 一个是scp.rb用来拷贝文件的,用法很简单:
scp.rb hostA:/tmp/afile ./ 或者
scp.rb afiel hostA:/tmp/afile
- 另外一个叫ssh_sudo.rb,看名字就知道,ssh来sudo的,比如:
ssh_sudo.rb hostA cat /etc/shadow 会在HostA上面执行 cat /etc/shadow
把ssh_sudo.rb中,15行换成:
15 channel.exec(”#{cmd}”) do | ch, success|
就成了普通版的ssh了。这两个可以解决我80%的问题了。剩下20%就根据情况,临阵定夺了
################## scp.rb #####################
#!/usr/local/bin/ruby
require ‘net/scp’
password=”real_password”
username=‘real_name’
src=ARGV[0]
dst=ARGV[1]
if ARGV[0] =~ /:/
host,remote_path=ARGV[0].split(”:”)
else
host,remote_path=ARGV[1].split(”:”)
end
Net::SCP.start( host, username, :password => password) do | scp |
if ARGV[0] =~ /:/
scp.download!( remote_path, dst )
else
scp.upload!( src, remote_path )
end
end
################## end scp.rb #####################
######################## ssh_sudo.rb #######################
#!/usr/local/bin/ruby
require ‘net/ssh’
password=”real_password”
username=‘real_name’
host=ARGV[0]
cmd=ARGV[1..ARGV.length-1].join(” “)
begin
#Net::SSH.start(host, username, :password=> password, :verbose => :debug ) do | session |
Net::SSH.start(host, username, :password=> password, :timeout=>3 ) do | session |
retry_count=0
session.open_channel do | channel|
channel.request_pty
channel.exec(”sudo #{cmd}”) do | ch, success|
#channel.exec(”echo ‘robert:$xxx.’ | sudo /usr/sbin/chpasswd -e”) do | ch, success|
abort “could not execute command” unless success
channel.on_data do | ch, data |
if data =~ /Password/
retry_count+=1
channel.send_data password+”\n”
else
puts data
end
end
channel.on_extended_data do |ch, type, data|
if data =~ /Password/
retry_count+=1
channel.send_data password+”\n”
end
end
channel.on_close do |ch|
puts “Error for #{host}” if retry_count > 1
end
end
end
end
rescue Exception
$stderr.print “Error: #{$!} on #{host}\n”
end
############# end of ssh_sudo.rb ###################
Del.icio.us : linux, net::ssh, ruby, ssh, sudo
一月 22nd, 2010 | Linux, SSH | No Comments »
这两种基于内存的文件系统,都可以称为内存盘。只是稍微有些差别:
Mount options for ramfs
Ramfs is a memory based filesystem. Mount it and you have it. Unmount it and it is gone. Present since Linux 2.3.99pre4. There are no
mount options.
Mount options for tmpfs
The following parameters accept a suffix k, m or g for Ki, Mi, Gi (binary kilo, mega and giga) and can be changed on remount.
size=nbytes
Override default maximum size of the filesystem. The size is given in bytes, and rounded down to entire pages. The default is
half of the memory.
nr_blocks=
Set number of blocks.
nr_inodes=
Set number of inodes.
mode= Set initial permissions of the root directory.
从挂载选项中可以看出两者最大的差别: tmpfs有size限制,ramfs没有size限制,换句话说: tmpfs不会耗光内存,因为有大小限制:超过物理
内存的时候会使用swap;而ramfs则有可能耗光物理内存,把机器拖垮,但是好处是会动态增长,适用于无法预估所需内存大小而内存又肯定够用的
情况,比如smarty的template_c;
Del.icio.us : linux, ramfs, tmpfs, unix
一月 20th, 2010 | Linux | No Comments »
bugzilla是不错,但是没有WYSIWYG的编辑器,实在寒酸
好在bugzilla的帮助文档中有一个列表,罗列出可链接书写格式的参考。
其中用处最多的就两项,想起了28原则:
comment3 -> comment3
Bug 178148 -> Bug 178148
Issue Linkable References
Linkable References enable the user to automatically link to another issue or comment via signal words. When you enter a linkable reference in the Additional Comments text box, Bugzilla automatically creates a link to that reference in the posted comment. Refer to the following table for the list of linkable entries and their respective signal words.
Note: A word followed by a + sign indicates that multiple words are required. A comma separating words indicates that any of those words work as a signal to Bugzilla. The signal words are not case-sensitive.
|
Linkable Reference
|
Single Words (not case sensitive)
|
|
Netapp bug
|
netapp + bug
|
|
Netapp case, log or ticket
|
netapp + case, log, ticket
|
|
Netapp Part Number
|
netapp, newtwork app
|
|
Netapp Syslog translator
|
[A valid syslog output]
|
|
CJ Account
|
ac, cid
|
|
FedEx Tracking Number
|
fedex, tracking
|
|
UPS Tracking Number
|
[A valid UPS tracking number starting with 1Z]
|
|
F5 Solution Id
|
f5 + SOL
|
|
RFC
|
rfc,bcp,std
|
|
Cisco Bug Id
|
[A valid Cisco ID starting with CSC]
|
|
Cisco TAC Case
|
cisco, tac + case,ticket
|
|
Cisco RMA
|
rma
|
|
Cisco Error message decoder
|
[A valid Cisco error message number]
|
|
IEEE OUI lookup (mac addresses)
|
[A valid mac address]
|
|
Telnet Command
|
telnet
|
|
Javadocs
|
[A valid javadoc reference]
|
|
Virus Name
|
[A valid virus name beginning with W32]
|
|
Dell Service Tag
|
[A valid service tag number]
|
|
Seagate Part Number
|
[A valid part number starting with ST]
|
|
Mojo Adserver Placement Id
|
rotation, placement
|
Del.icio.us : Issue Linkable References, bugzilla
一月 19th, 2010 | 生活小札 | No Comments »
一台server上面碰到比较奇怪的问题,
执行很多命令的时候,老是提示:Too many levels of symbolic links
结果一番调查,实在不得要领,没有任何结果,后来安装ruby的时候
configure无法通过,报错:C compiler cannot create executables
这个问题的出现一般是gcc相关的包比如glibc、kernel-header、之类的包没有安装导致
但是这些包都确认安装过了,
在config.log中发现:
checking for gcc… gcc
checking for C compiler default output file name…
configure: error: C compiler cannot create executables
See `config.log’ for more details.
configure:2525: checking for C compiler default output file name
configure:2552: gcc conftest.c >&5
gcc: error trying to exec ‘as’: execvp: Too many levels of symbolic links
不是C compiler无法创建可执行文件,而是”Too many levels of symbolic links”这个老问题。
后来发现PATH设置有些异常,满屏幕的都是/usr/java/default/bin。 突然想起
这个服务器上面的java安装曾经出现过异常,在/etc/profile中出现了大量重复的
export JAVA_HOME=/usr/java/default
export PATH=$JAVA_HOME/bin:$PATH
在/usr/java下一查看才发现罪魁祸首所在:default这个死循环的软连接
12/24/09 18:43:39 [ /usr/java ]
—> root@saxxmnt02 (1.84)# ll
total 8
lrwxrwxrwx 1 root root 17 Mar 30 2009 default -> /usr/java/default
lrwxrwxrwx 1 root root 16 Mar 30 2009 latest -> /usr/java/latest
12/24/09 18:43:39 [ /usr/java ]
/u0/gavin/bin:/u0/gavin/local/bin:/usr/kerberos/bin:/usr/java/latest/bin:/usr/local/bin:/bin:/usr/bin:
删掉这个死连接,一切都恢复了。
Del.icio.us : LAMP Linux
十二月 26th, 2009 | 生活小札 | No Comments »