Articles of shell

电子邮件正文中的PowerShell电子邮件日志文件

我正在使用这个Power-Shell脚本来发送电子邮件。 我的问题是与$ bodyvariables。 我不想在电子邮件中附加日志文件,我希望日志文件的内容位于电子邮件的正文中。 Write-Host "Setting Variables" -ForegroundColor Green $user = "username" $pass = Get-Content "$PSScriptRoot\pass.txt" | ConvertTo-SecureString $cred = New-Object -Typename System.Management.Automation.PSCredential -argumentlist $user,$pass $from = "[email protected]" $to = "[email protected]" $subject = "Email Subject" $body = Get-Content C:\backup\log.txt $smtp = "smtp.gmail.com" Write-Host "Sending Email" -ForegroundColor Green Send-MailMessage -From $from -To $to -Subject $subject -Body […]

nano / vi打开写保护文件作为未经授权的用户 – 我可以升级保存吗?

更多的时间比我想承认我会打开一个非超级用户的configuration,并会去做我需要的改变。 只要我保存在纳米,或六我遇到权限错误。 在这一点上,我用我的方式,所以我可以closures并重新打开与sudo 。 有没有办法升级到超级用户为了保存而不closures和重新打开vi或nano?

sed:-eexpression式未知选项到's'

我知道这已经被问过,但我正努力确定错误的根本原因与我的脚本。 我经历了其他问题,并试图转换(切换/ \为@),但它只是不起作用,我仍然得到相同的错误? 只要我在最后4(从底部)joinexpression式,我开始得到错误,.. 当我运行这个 clustername="'XXXCluster'" seed=xx.xxx.xxx.xx ip=xx.xxx.xxx.xx hint="/opt/cassandra/data/hints" data="/opt/cassandra/data/data" commitlog="/opt/cassandra/data/commitlog" cache="/opt/cassandra/data/saved_caches" sed -i -e "s/\(cluster_name:\).*/\1$clustername/" \ -e "s/\(- seeds:\).*/\1$seed/" \ -e "s/\(listen_address:\).*/\1$ip/" \ -e "s/\(rpc_address:\).*/\1$ip/" \ -e "s/\(broadcast_rpc_address:\).*/\1$ip/" \ -e "s/\(hints_directory:\).*/\1$hint/" \ -e "s/\(data_file_directory:\).*/\1$data/" \ -e "s/\(commitlog_directory:\).*/\1$commitlog/" \ -e "s/\(saved_caches_directory:\).*/\1$cache/" /opt/cassandra.yaml 我得到这个sed:-eexpression式#6,字符29:未知选项's' 但我不能看到如何解决这个问题,有人可以帮我吗? 提前致谢..

在创build脚本来更新/ etc / hosts文件中的主机名时遇到多个问题?

我完全是新的脚本,因此需要帮助解决这个问题。 我们有大约3000台虚拟机和450台物理服务器,这些服务器都是基于Linux的服务器(从9.x开始很less有Ubuntu的服务器,其中很less有Susu从8.x开始,大部分是从4.x开始到7.4的RHEL)所有他们我需要添加与IP详细信息到他们各自的/ etc / hosts文件几个主机名项。 我有不同的用户在每个服务器上有完整的sudoers访问,我可以使用因此,我创build了一个主机名,用户名和密码格式的CSV文件。 其中包含需要login的详细信息。文件名是“hostname_logins.csv” 我需要上传一个文件(即hostname_list到这些服务器中的每一个,然后在每个服务器主机文件中更新这些相同的细节。 我将使用一个RHEL 6服务器运行此脚本。 (所有其他主机都可以从这台服务器parsing,可以到达,我已经确认了。) 因此需要帮助解决这个脚本。 脚本不知道有什么问题,因为我是一个新的脚本: #!/bin/bash while read hostname_login user_name user_password do scp -p ./hostname_list $user_name:$user_password@$hostname_login:/tmp ssh -eS $user_name:$user_password@$hostname_login [bash -c "echo rishee | sudo -S mv /tmp/hostname_list ./hostname_list && cp -p /etc/hosts /etc/hosts.bkp && cat ./hostname_list >> /etc/hosts && rm -f ./hostname_list"] done < hostname_logins.csv 我需要把它作为一个单独的脚本,可以在所有这些服务器上运行。 […]

PowerShell Active Directory用户更新

我试图更新CSV中所有用户的-msDS-cloudExtensionAttribute。 CSV示例 AD CA11 CA10 CA9 User1 none none technician User2 none engineer technician User3 responsible engineer technician User4 none none none User5 none none none User6 responsible none technician User7 none none none User8 none engineer none User9 none none none User10 none none technician 我使用set-ADUSer,但它不能识别属性。 Import-CSV c:\temp\all.csv | Foreach { Set-ADUSer -Identity $_.AD […]

猫,pipe和acroread – 为什么它偶尔失败?

在一个简单的shell脚本我试图运行这个命令: cat /filelocation/myoutput.PDF | /opt/Adobe/Acrobat7.0/bin/acroread -toPostScript 在大多数情况下,这是工作。 但偶尔,我得到一个错误: lp: standard input is empty lp: request not accepted Broken pipe cat: Cannot write to output. 这似乎只发生在负载繁重的情况下,我们正在处理大量的pdfrecursion。 (用不同的文件反复调用所述shell命令)

为什么这个脚本没有列出组成员的工作?

我一定在做一些愚蠢的事情,但是如果我能看到什么的话,我会很尴尬的。 根据我的谷歌search这个Powershell脚本应该列出域用户组的成员: $root=([ADSI]"").distinguishedName $group = [ADSI] ("LDAP://cn=Domain Users,cn=Users," + $root) Write-Host $group.distinguishedName Write-Host "Members:" foreach ($member in $group.member) { $member } 但是当我运行它时,我只是得到输出: CN=Domain Users,CN=Users,DC=mydomain,DC=local Members: 所以它find了组,但没有列出成员。 我已经在Server 2003和Server 2008上试了这个,我不知道我明显的错误在哪里。 请帮忙 … JR

需要编写Linux程序来获得基本的系统统计信息

我花了很多时间手动报告从Cacti监测工具和/或Top和ps命令获得的基本Linux系统状态。 我基本上是用以下格式写一个报告: Host: <name value> CPU Util: <value> (if Idle % is 100 – 60% print "Good" ; if Idle % is 60 – 30% print "Fair"; if Idle % is 30 – 0% print "Bad") Memory Util: <value> (if Free Mem % is 100 – 60% print "Good" ; if Free Mem % is […]

如何中止第一个错误的robocopy

当使用robocopy的Windows实用程序,我设置了什么标志,以便robocopy放弃它看到的第一个错误,类似于xcopy / dry命令? 我需要镜像两个dirs,有时一些文件将被locking。 我不希望robocopy继续尝试复制文件,或者覆盖未被locking的文件 – 而第一个错误应该会停止整个复制过程。

从日志文件中提取信息进行聚合

给定以下格式的日志 2009-11-11 13:13:44,716 INFO Something happened : problem description . Waited 3 seconds 2009-11-11 13:23:44,716 INFO Something happened : problem description . Waited 1 second 2009-11-11 13:33:44,716 INFO Something happened : some other problem description . 我怎样才能提取之间的string:和. ?