我想删除Ubuntu 8.04服务器上的一些文件夹.
我想启动一个脚本来删除这个文件夹.
我启动了一个ssh会话到服务器.
我的脚本看起来像这样:
#!/bin/bash
rm -r /var/lib/backuppc/pc/PC1/
rm -r /var/lib/backuppc/pc/PC2/
Run Code Online (Sandbox Code Playgroud)
我像这样运行脚本:
sh scriptname.sh
Run Code Online (Sandbox Code Playgroud)
但是我得到了这样的信息:
rm: cannot remove `/var/lib/backuppc/pc/PC1/\r': No such file or directory
rm: cannot remove `/var/lib/backuppc/pc/PC1/\r': No such file or directory
Run Code Online (Sandbox Code Playgroud)
对不起,我不会在linux上使用shell脚本.我认为这是我的错,因为我不知道基础知识:-(
有人能帮助我吗?我要删除~80文件夹...... :-(
我想使用shell脚本在"yyyy-mm-dd hh:mm:ss"格式中传递时间戳,我的意思是从shell脚本我将调用我的jar文件并将参数作为参数传递,所以我做的就像 -
DATE=`date +%Y-%m-%d" "%H:%M:%S`
spark-submit --jars ./mylibs/log4j-1.2.17.jar --class com.mycom.test.jobtest.agg myApp-.0.1.jar $DATE
Run Code Online (Sandbox Code Playgroud)
如果我接受DATE的回应它将给出正确的日期作为预期的格式"yyyy-mm-dd hh:mm:ss"但是在java中解析时它正在考虑空间并且只考虑日期部分,并且在下面给出错误 -
Exception in thread "main" java.text.ParseException: Unparseable date: "2015-03-08"
Run Code Online (Sandbox Code Playgroud)
请建议传递时间戳作为参数的最佳方法,
我刚刚通过Hartl教程的第8章,但在我尝试运行测试时仍然遇到错误.我得到3个相同的错误,问题似乎源于用户登录测试,其中夹具:michael未在夹具集(用户)中找到.
这是我的user_login_test
require 'test_helper'
class UsersLoginTest < ActionDispatch::IntegrationTest
def setup
@user = users(:michael)
end
test "login with invalid information" do
get login_path
assert_template 'sessions/new'
post login_path, session: { email: "", password: "" }
assert_template 'sessions/new'
assert_not flash.empty?
get root_path
assert flash.empty?
end
test "login with valid information" do
get login_path
post login_path, session: { email: @user.email, password: 'password' }
assert_redirected_to @user
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(@user)
end
end
Run Code Online (Sandbox Code Playgroud)
这是错误
ERROR["test_login_with_invalid_information", UsersLoginTest, …Run Code Online (Sandbox Code Playgroud) 当我得到bash输出时,我得到了标准的2色屏幕。默认情况下,如果其中包含一些关键文本输出,有什么办法可以使我突出显示一行?
例如,如果其中包含单词“ FAIL”,则该行将显示为红色。
我已经读过这个https://unix.stackexchange.com/questions/46562/how-do-you-colorize-only-some-keywords-for-a-bash-script, 但我正在寻找比写简单的东西包装脚本,将来不可避免地需要调试。
我有以下代码:
function replaceappend() {
awk -v old="$2" -v new="$3" '
sub(old,new) { replaced=1 }
{ print }
END { if (!replaced) print new }
' "$1" > /tmp/tmp$$ &&
mv /tmp/tmp$$ "$1"
}
replaceappend "/etc/ssh/sshd_config" "Port" "Port 222"
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但我希望修改它,以便awk命令只在行以该结果开头时才找到匹配项.所以,如果它正在寻找"端口"这个词:
Port 123 # Test <- It would match this one
This is a Port <- It would not match this one
Run Code Online (Sandbox Code Playgroud)
我试着看看其他帖子,询问有关"awk行开头"的帖子,比如这个,但我无法理解它:
任何人都可以告诉我有什么区别
cmd1 & cmd2 & ...
和
cmd1 && cmd2 && ....
在shell脚本中.如果它们的执行不同,我可能知道每个命令是如何实际执行的.
我是Ubuntu和bash脚本的新手,但我刚刚创建runUpdates.sh并将其添加到我.profile运行它:
if [ -f "$HOME/bin/runUpdates.sh" ]; then
. "$HOME/bin/runUpdates.sh"
fi
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,我希望脚本像root运行一样运行(因为我不想输入我的sudo密码)
我发现了几个地方,我应该能够做到sudo chown root.root <my script>并且sudo chmod 4755 <my script>,当我运行它,它应该以root身份运行.但它不是......
这个脚本对我来说很好看.我错过了什么?-rwxr-xr-x 1 root root 851 Mar 23 21:14 runUpdates.sh*
你可以帮助我以root身份运行这个脚本中的命令吗?我真的不想更改sudors文件,我真的只想在root下运行这个脚本中的命令(如果可能的话).
#!/bin/sh
echo "user is ${USER}"
#check for updates
update=`cat /var/lib/update-notifier/updates-available | head -c 2 | tail -c 1`;
if [ "$update" = "0" ]; then
echo -e "No updates found.\n";
else
read -p "Do you wish to install updates? [yN] " …Run Code Online (Sandbox Code Playgroud) 我试图返回我的MONTHNO变量中指定月份的月份的最后一天.
因此,当MONTHNO指向二月时,例如我们四月份YYYYMMDD应该返回20150228
MONTHNO=`date -d "2 month ago" "+%m"`
YEAR=`date +%Y`
YYYYMMDD=`date +%Y%m%d`
Run Code Online (Sandbox Code Playgroud)
谢谢
我使用shell脚本将MySQL查询的输出存储在varible中.SQL查询的输出是多行.当我检查变量的计数(我认为是一个数组)时,它给出了1.我的代码片段如下:
sessionLogin=`mysql -ugtsdbadmin -pgtsdbadmin -h$MYSQL_HOST -P$MYSQLPORT CMDB -e " select distinct SessionID div 100000 as 'MemberID' from SessionLogin where ClientIPAddr like '10.104%' and LoginTimestamp > 1426291200000000000 order by 1;"`
echo "${#sessionLogin[@]}"
Run Code Online (Sandbox Code Playgroud)
如何在shell脚本中将MySQL查询输出存储在数组中?
我遇到了关于"ls"这个命令的一些问题
我想只打印没有隐藏或链接的目录
但我用男人来看看解释,但我没找到
如果有一面旗帜,我可以做我想做的事......
谢谢
以下是我要解决的问题......
4.显示可见的出口
This is two commands: The first command prints "Visible exits: "
-> It must not advance the cursor to the next line.
The second command displays the visible exits and then a period (.).
-> To prevent the linked directories contents from also displaying, you
will need a flag.
-> Several wildcard patterns will be needed.
-> The period will be the last of these patterns.
The period means the current directory. But …Run Code Online (Sandbox Code Playgroud)