我正在尝试安装 postgresql 并在部署时为其生成随机密码,仅供测试之用。像这样的东西:
$DBPASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
sudo -u postgres -H createuser --no-createrole --no-superuser --no-createdb $NAME
sudo -u postgres -H createdb -O $PROJECT $PROJECT
sudo -u postgres -H psql -c "alter user $PROJECT with password '$DBPASS'"
Run Code Online (Sandbox Code Playgroud)
我得到的错误是这样的:
=b3wDxlSbUymho0CmOZ4TgPylLCanKdgJ:未找到命令 /usr/lib/postgresql/9.1/bin/createdb:选项需要参数 -- 'O' 尝试“createdb --help”以获取更多信息。
错误:“使用密码”
第 1 行或附近存在语法错误:使用密码“更改用户”
任何人都可以解释为什么会发生这种情况吗?
我对 Linux 比较陌生,所以这可能是一个简单的问题,但是当我在 git 提交消息周围使用引号(单引号或双引号)时,这些单词将被视为文件名。如何在消息中使用带有空格的 -m - 我不想使用 vi。
\n\nuser@linux:~/Documents/tmp$ git status\n\nOn branch master\n\nInitial commit\n\nChanges to be committed:\n (use "git rm --cached <file>..." to unstage)\n\n new file: afile\n\nuser@linux:~/Documents/tmp$ git commit -m \xc2\xa8this message has spaces and fails\xc2\xa8 \n\nerror: pathspec \'message\' did not match any file(s) known to git.\n\nerror: pathspec \'has\' did not match any file(s) known to git.\n\nerror: pathspec \'spaces\' did not match any file(s) known to git.\n\nerror: pathspec \'and\' did not match any file(s) known to git.\n\nerror: pathspec …Run Code Online (Sandbox Code Playgroud) 我有一个 json 文件,其结构如下所示:
{
url: "https://mysite.com/myjsonfile",
version_number: 69,
}
Run Code Online (Sandbox Code Playgroud)
此 json 文件可从 mysite.com/myrootjsonfile 访问
我想运行加载数据脚本来访问 mysite.com/myrootjsonfile 并使用curl 从 url 字段加载 json 内容,并将结果内容保存到本地存储。
这是我迄今为止的尝试。
curl -o assets/content.json 'https://mysite.com/myrootjsonfile' | grep -Po '(?<="url": ")[^"]*'
Run Code Online (Sandbox Code Playgroud)
不幸的是,它不是保存 mysite.com/myjsonfile 中的内容,而是保存上面的内容:mysite.com/myrootjsonfile。谁能指出我可能做错了什么?请记住,在全新的卷曲中。谢谢!
@ECHO OFF
set /A q=0
for /F "tokens=*" %%E IN ('findstr /n /r "Finshed With Errors" D:\DataUploadUtil\UploadStatus\TariffUploadLog.txt') do (
set array[!q!]=%%E
set /A q=q+1
echo %%E >>D:\DataUploadUtil\UploadStatus\AllTariffsUploadStatus.txt
set test=%%E
echo %test% ::error
)
Run Code Online (Sandbox Code Playgroud)
在上面的脚本中,我尝试在循环中打印测试,其显示 ECHO IS OFF。我想打印测试变量
谢谢
PASE环境默认提供并使用 korn shell。ibmpaseforishell变量可用于更改默认值,但这适用于所有用户。使用 SSH 登录时如何更改用户的默认 shell?
如何使用 shell 脚本将零填充为二进制数。
二进制.txt
1010011100010001010111001101111
0
10110000000101000000000000001
10100000011
1000000100
1111111111111111
11111111111111110000000000000000
11111111111111110000000000000000
11111111111111110000000000000000
11111111111111110000000000000000
11111111111111110000000000000000
11111111111111110000000000000000
11111111111111110000000000000000
11111111111111110000000000000000
11111111111111110000000000000000
11111111111111110000000000000000
Run Code Online (Sandbox Code Playgroud)
当我执行以下操作时
printf "%032s\n" $(<binary.txt)
Run Code Online (Sandbox Code Playgroud)
我得到一个空白。
1010011100010001010111001101111
0
10110000000101000000000000001
10100000011
1000000100
1111111111111111
11111111111111110000000000000000
11111111111111110000000000000000
11111111111111110000000000000000
Run Code Online (Sandbox Code Playgroud)
但我需要附加零。任何意见都会受到赞赏。谢谢,
更新:
binary.txt 是我的输入文件,具有以下内容。
1010011100010001010111001101111
0
10110000000101000000000000001
10100000011
1000000100
1111111111111111
11111111111111110000000000000000
11111111111111110000000000000000
Run Code Online (Sandbox Code Playgroud)
在命令行中运行以下命令时,它工作正常。
printf "%032s\n" $(<binary.txt) | tr ' ' '0' >> t1.mif
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用下面的脚本执行相同操作时,它给了我错误的值。有什么建议。
#!/bin/bash
FILE=binary.txt
while read line;do
printf "%032s\n" $line | tr ' ' '0' >> t1.mif
done < $FILE
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在尝试在 postgres 帐户下通过 psql 执行 SQK。我可以运行不包含引号的 SQL
root@server:/home/rosta/SCRIPTS# su postgres -c "psql -c 'SELECT NOW()'"
now
-------------------------------
2014-06-07 09:38:17.120368+02
(1 row)
Run Code Online (Sandbox Code Playgroud)
该问题出现在包含 SELECT 'hi' 等引号的 SQL 查询中。我正在使用简单的“hi”进行测试,但我想从 shell 脚本执行类似的操作。
su postgres -c "psql -c 'create database $DB_NAME template=template0 encoding='utf8' owner=aaa lc_collate='cs_CZ.utf8''"
Run Code Online (Sandbox Code Playgroud)
谁能告诉我如何在上面的命令中转义编码和整理的引号
我的一些测试:
root@server:/home/rosta/SCRIPTS# su postgres -c "psql -c 'SELECT \'hi\''"
bash: -c: line 0: unexpected EOF while looking for matching `''
bash: -c: line 1: syntax error: unexpected end of file
root@server:/home/rosta/SCRIPTS# su postgres -c "psql -c 'SELECT \\'hi\\''" …Run Code Online (Sandbox Code Playgroud) 我有这个 NodeJS 脚本:
var util = require('util'),
process = require('child_process'),
ls = process.exec('test.sh');
ls.stdout.on('data', function (data) {
console.log(data.toString());
ls.stdin.write('Test');
});
Run Code Online (Sandbox Code Playgroud)
和这个 shell 脚本:
#!/bin/bash
echo "Please input your name:";
read name;
echo "Your name is $name";
Run Code Online (Sandbox Code Playgroud)
我尝试运行 NodeJS 脚本,但它卡在“请输入您的名字:”处。有谁知道如何将 NodeJS 脚本的输入发送到 shell 脚本?
谢谢
我正在尝试找出一种方法来更改由 GPG 对称加密的文件的密码,而无需使用临时文件或 shell 变量。我知道我可以在带有变量的 shell 函数中执行此操作,但如果可能的话,我想在命令行上执行此操作。
我认为这应该是可能的,因为 GPG 会使用 加密传入的流,gpg --symmetric -o example.gpg并且因为 GPG 会使用 将解密的输出发送到 STDOUT gpg --decrypt。
但这不能正常工作:
gpg --decrypt example.gpg | gpg --symmetric -o new.gpg
Run Code Online (Sandbox Code Playgroud)
我认为我对 shell 操作顺序和重定向的理解是错误的。Enter passphrase:特别是因为 shell 输出一次有多个提示。
以下是输入管道命令后的初始交互响应:
localhost ~% gpg --decrypt example.gpg | gpg --symmetric -o example.gpg
gpg: CAST5 encrypted data
Enter passphrase: Enter passphrase
Run Code Online (Sandbox Code Playgroud)
之后,我会收到各种密码提示...有时会要求我输入解密密码,然后我可以以可见的纯文本形式输入新密码,然后输入隐藏的新密码确认。有时,在要求我提供解密密码之前,我会收到新密码对话框。
我认为存在竞争条件。
有什么建议吗?
shell ×10
bash ×3
linux ×3
postgresql ×2
arrays ×1
batch-file ×1
binary ×1
command-line ×1
curl ×1
debian ×1
encryption ×1
escaping ×1
git ×1
gnupg ×1
ibm-midrange ×1
javascript ×1
loops ×1
node.js ×1
printf ×1
psql ×1
scripting ×1
unix ×1
vxworks ×1