AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-346682

John Smith's questions

Martin Hope
John Smith
Asked: 2024-12-25 19:38:02 +0800 CST

我怎样才能使这个预期脚本始终按预期工作?

  • 8

我使用Spectrespectre-cli的交互式钱包,这种代币的设计与 Kaspa 类似。当我想要手动获取钱包余额时,我需要 在 中运行,然后运行​​。所有这些看起来都像这样:spectre-cliconnectopenspectre-cli

spectre-cli
Spectre Cli Wallet v0.3.16 (type 'help' for list of commands)
$ connect
Connected to Spectre node version 0.3.16 at ws://127.0.0.1:19110
$ open
Enter wallet password: 

Your wallet hint is: This is a hint.

$ $ 
• ****************
    • [********]: 4.47042578 SPR   1 UTXOs
      spectre:******************************************************

[********] • 4.47042578 SPR $ 

我编写了一个预期脚本来帮我完成这些步骤(这样我唯一需要输入的就是我的密码):

#!/usr/bin/expect -f

# Set a timeout (in seconds) for how long to wait for each prompt
set timeout 5

spawn spectre-cli

expect "$ "   
send "connect\r"

expect "$ "  
send "open\r"


interact

我从脚本中得到不一致的输出。大约 70% 的时间我得到:

./get_balance_works.exp 
spawn spectre-cli
Spectre Cli Wallet v0.3.16 (type 'help' for list of commands)
$ connect
connectopen
command not found: connectopen
$ 

其余时间脚本都按预期工作:

./get_balance_works.exp 
spawn spectre-cli
Spectre Cli Wallet v0.3.16 (type 'help' for list of commands)
$ connect
$ open
Connected to Spectre node version 0.3.16 at ws://127.0.0.1:19110
Enter wallet password: 

Your wallet hint is: This is a hint.

$ $ 
• ****************
    • [********]: 4.47042578 SPR   1 UTXOs
      spectre:******************************************************

[********] • 4.47042578 SPR $ 

有没有办法让脚本以一致的方式按预期工作?

PS 我在使用 Ubuntu LTS。

scripting
  • 2 个回答
  • 58 Views
Martin Hope
John Smith
Asked: 2024-06-09 21:06:21 +0800 CST

为什么将“umask”设置为“0077”(然后下载公钥)会导致 apt 无法使用 gpg 公钥?

  • 7

为什么设置umask为会导致安装包0077时gpg 公钥不可用,例如。apt

umask 0077
curl -fsSLo /usr/share/keyrings/brave-browser-beta-archive-keyring.gpg https://brave-browser-apt-beta.s3.brave.com/brave-browser-beta-archive-keyring.gpg
  echo "deb [signed-by=/usr/share/keyrings/brave-browser-beta-archive-keyring.gpg] https://brave-browser-apt-beta.s3.brave.com/ stable main">/etc/apt/sources.list.d/brave-browser-beta.list
apt update
apt install brave-browser-beta
  

上述操作不起作用,我得到了这个输出:

Err:4 https://brave-browser-apt-beta.s3.brave.com stable InRelease    
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0B31DBA06A8A26F9
Reading package lists... Done
W: GPG error: https://brave-browser-apt-beta.s3.brave.com stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0B31DBA06A8A26F9
E: The repository 'https://brave-browser-apt-beta.s3.brave.com stable InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.


这确实有效:

umask 0022
curl -fsSLo /usr/share/keyrings/brave-browser-beta-archive-keyring.gpg https://brave-browser-apt-beta.s3.brave.com/brave-browser-beta-archive-keyring.gpg
  echo "deb [signed-by=/usr/share/keyrings/brave-browser-beta-archive-keyring.gpg] https://brave-browser-apt-beta.s3.brave.com/ stable main">/etc/apt/sources.list.d/brave-browser-beta.list
apt update
apt install brave-browser-beta

为什么设置umask为0077(然后下载公钥) 会导致 apt 无法使用 gpg 公钥?密钥是作为 下载的root,因此被执行apt update,那么为什么会出现这个问题?

permissions
  • 1 个回答
  • 39 Views
Martin Hope
John Smith
Asked: 2024-02-18 18:35:01 +0800 CST

为什么当我尝试访问 bitcoin.stackexchange.com 及其 /etc/hosts 中的 IP 别名时,浏览器会出现不同的行为?

  • 5

我还没有发现任何浏览器支持定义的别名,/etc/hosts即使单个术语(无需在浏览器中预先添加http://)不被解释为默认搜索引擎的搜索术语(badwolf browser的情况)也是如此。别名在前缀为 http:// 时有效,例如, http://bse但必须键入http://会破坏使用它们的目的。

Cloudflare 不允许通过别名访问 bitcoin.stackexchange.com,定义为 172.64.144.30 bitcoin.stackexchange.com bse

Error 1003 Ray ID: 85750e9fc9b65e4d • 2024-02-18 08:56:29 UTC
Direct IP access not allowed
What happened?
You've requested an IP address that is part of the Cloudflare network. A valid Host header must be supplied to reach the desired website.

当我尝试访问时,bitcoin.stackexchange.com我没有从 Cloudflare 收到任何错误。

  1. bitcoin.stackexchange.com当我尝试从台式电脑访问并附加到 时,我是否发送主机标172.64.144.30 bitcoin.stackexchange.com bse头/etc/hosts?

  2. 为什么我在尝试访问浏览器时会得到不同的浏览器http://bse行为bitcoin.stackexchange.com?

  3. Brave、Firefox (?)、Chromium 等浏览器中是否有任何设置about:config可以让我无缝地使用我的别名?

除了/etc/hosts我的 DNS 查询之外,其他查询均由家庭路由器解析,如我的内容所示/etc/resolv.conf

# Generated by Connection Manager
search home 
nameserver 192.168.1.1

我所做的研究是man hosts。附加的假设目的172.64.144.30 bitcoin.stackexchange.com bse是/etc/hosts限制对我的路由器的 dns 服务器的某些 DNS 查询的数量(这可能使我的分析看起来过于激进,从而导致有针对性的监视)。我知道反向 DNS 查找的可能性,但这超出了问题的范围。

dns
  • 1 个回答
  • 53 Views
Martin Hope
John Smith
Asked: 2024-02-17 00:14:01 +0800 CST

如何以非交互方式(从脚本)验证与 openssl 的 ssl / tls 连接?

  • 8

当我执行时:

openssl s_client -connect google.com:443
openssl s_client -connect government.ru:443

这给了我有价值的输出,但我想openssl关闭连接并退出返回一个整数退出代码(不同),以便我可以这样做

echo "Domain?";read d
openssl s_client -connect "$d":443

if [[ "$?" -eq 0 ]]; then
  echo "Encrypted"; do_sth
else 
  echo "Plain."; do_sth_else
fi

openssl
  • 2 个回答
  • 70 Views
Martin Hope
John Smith
Asked: 2024-01-08 15:55:14 +0800 CST

如何将只能安装到 /etc/fstab 中具有条目的驱动器/分区列入白名单?

  • 11

在我的 Ubuntu 系统上,我注意到某些文件管理器在打开时可以挂载通过我的 USB 端口之一(作为非 root)连接的任何驱动器。为了防止这种情况发生,我/etc/fstab这样配置:

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/vgubuntu-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/nvme0n1p3 during installation
UUID=485794d0-6773-4136-9df9-c8f97fc3c3bc /boot           ext4    defaults        0       2
# /boot/efi was on /dev/nvme0n1p2 during installation
UUID=5E62-20EC  /boot/efi       vfat    umask=0077      0       1
/dev/mapper/vgubuntu-swap_1 none            swap    sw              0       0
#/media/j/sandisk-32GB is my primary USB drive for backups
PARTUUID=d199a40a-b5cc-724b-b70b-1b90e4274ea9 /media/user_xyz/sandisk-32GB ext4 defaults,nofail 0 3

1. 如何防止非用户自动挂载或挂载my 中未root指定的驱动器/分区?/etc/fstab

2.是否可以进一步限制root安装白名单以外的驱动器?例如,root尝试执行mount PARTUUID=this-partition-is-not-whitelisted /media/user_xyz/not-whitelisted并失败,除非他们更改我尝试设置的配置。

PS这个特殊的PARTUUID只是用来传达我的意思 - 我知道它的格式不正确,因此root会导致安装失败。我使用的是 Ubuntu 22.04 LTS。

filesystems
  • 2 个回答
  • 282 Views
Martin Hope
John Smith
Asked: 2024-01-01 21:33:52 +0800 CST

如何使用非标准文件描述符通过映射文件将文件读入数组?

  • 6

mapfile -t -u 7 arr < textfile给我 bash: mapfile: 7: invalid file descriptor: Bad file descriptor 其他更详细的逐行读取文件的方法确实允许这样的描述符,例如

read_w_while() {
while IFS="" read -u 7 -r l || [[ -n "${l}" ]]; do
  echo "${l}"
done 7< textfile

标准描述符0被大量使用。使用这样的描述符是否可以使脚本编写更安全,免受干扰?我的经验是,到目前为止,我只目睹过,我是 Ubuntu 桌面用户,在使用while IFS="" read -u 7 ...描述符时出现这种干扰7。造成这种干扰的原因可能是什么?

bash
  • 2 个回答
  • 68 Views
Martin Hope
John Smith
Asked: 2023-12-09 19:26:16 +0800 CST

如何在 crontab 中声明和使用保存管理员用户帐户名称的变量?

  • 5

我希望 crontabroot是不可知的,即我不想在其中逐字指定 admin 用户是jim。这就是为什么在我的 crontab 中root引入了变量au。

SHELL=/bin/bash

PATH=/usr/bin:/bin:/usr/sbin:/sbin

au=$(echo "$(head -n 1 /etc/doas.conf)"|sed 's/permit//;s/as//;s/root//;s/ //g')

5 */4 * * * /home/"${au}"/sync-w-oumaima.sh
* * * * * echo "$au">"/home/${au}/${au}.log"

遗憾的是,它不起作用——/home/jim/jim.log不是由 crontab 创建的。如何在 crontab 中声明和使用保存管理员用户帐户名称的变量?

bash
  • 2 个回答
  • 58 Views
Martin Hope
John Smith
Asked: 2023-12-09 04:38:07 +0800 CST

SSH 的 -t 选项 - 如何远程执行包含管道和变量扩展的复杂命令?

  • 5

以下脚本由 jim 的计算机运行root,旨在将两个目录共享到 oumaima 的计算机。

#!/usr/bin/bash

au=$(echo "$(head -n 1 /etc/doas.conf)"|sed 's/permit//;s/as//;s/root//;s/ //g') 

dirs=(
"/var/lib/transmission-daemon/downloads"
"/home/${au}/VisualArts/films_FR"
)



dst_ip="[fe80::cc08:9467:8dba:15a9%wlp4s0]"
her_host="fe80::cc08:9467:8dba:15a9%wlp4s0"

give_oumaima() {
for d in ${dirs[@]}; do 
  rsync -e "ssh -6 -i /home/${au}/.ssh/id_rsa" -av --delete --no-o --no-g --chown=oumaima:oumaima "${d}" "root@${dst_ip}:/home/oumaima/Desktop" &&
  ssh -i "/home/${au}/.ssh/id_rsa" -t -6 "root@${her_host}"  'echo -e "${d} synced, $(date)."|tee -a "/root/syncing-w-${au}.log"'
done
}

give_oumamima

/root/syncing-w-.log在远程主机上创建日志文件,其内容为:

 synced, Fri Dec  8 20:05:15 CET 2023.
 synced, Fri Dec  8 20:52:57 CET 2023.
 synced, Fri Dec  8 20:52:58 CET 2023.
 synced, Fri Dec  8 21:01:37 CET 2023.

au和等变量d不会扩展为jim(我的电脑的管理员用户)和目录名称。这个结果长期被创建为/root/syncing-w-.log而不是/root/syncing-w-jim.log. 此外,日志的内容对于 复制的目录并不特定rsync。看来单引号是罪魁祸首,但我该如何重写'echo -e "${d} synced, $(date)."|tee -a "/root/syncing-w-${au}.log"'以使变量扩展呢?

bash
  • 1 个回答
  • 40 Views
Martin Hope
John Smith
Asked: 2023-11-17 17:15:55 +0800 CST

如何正确定义此变量并将其插入到我的 find 命令中?[复制]

  • 5
这个问题在这里已经有了答案:
在 bash 中构建外部命令的可变长度参数行的正确方法 (2 个答案)
3 天前关闭。

我编写了一个 Bash 脚本,mscript.sh用于管理我的音乐文件,其中一部分创建了此类文件的列表。

all_exts=" -iname \"*.webm\" -o -iname \"*.mkv\" "
#all_exts=' -iname "*.webm" -o -iname "*.mp3" -o -iname "*.mp4" -o -iname "*.mkv" ' 
#The line below works fine
#find "${HOME}/pCloudDrive/SocialSciences/Arabic/al_aghani" -maxdepth 1 -type f -size +1M \( -iname "*.webm" -o -iname "*.mp3" -o -iname "*.mp4" -o -iname "*.mkv" \)|\
find "${HOME}/pCloudDrive/SocialSciences/Arabic/al_aghani" -maxdepth 1 -type f -size +1M \( "$all_exts" \)|\
awk -v FS="/" '{print $8}' > "${HOME}/pCloudDrive/SocialSciences/Arabic/al_aghani/list"
#it does not work with single quotes either

我得到以下输出, find: paths must precede expression: -iname "*.webm" -o -iname "*.mkv" ' 当我运行脚本而不尝试插入all_exts我的 find 命令时,脚本工作正常。我如何正确扩展all_exts?PS 这个脚本很简单只是为了隔离问题。我确实需要插入all_extsfind 命令,因为我有许多 find 命令在许多不同的目录中执行这项工作。

bash
  • 1 个回答
  • 25 Views
Martin Hope
John Smith
Asked: 2023-11-08 18:30:26 +0800 CST

为什么 gawk -d 不在我当前的工作目录中创建 awkvars.out ?

  • 5

gawk -d不在我当前的工作目录中创建。awkvars.out为什么?相反,我得到以下标准输出:

Usage: gawk [POSIX or GNU style options] -f progfile [--] file ...
Usage: gawk [POSIX or GNU style options] [--] 'program' file ...
POSIX options:      GNU long options: (standard)
    -f progfile     --file=progfile
    -F fs           --field-separator=fs
    -v var=val      --assign=var=val
Short options:      GNU long options: (extensions)
    -b          --characters-as-bytes
    -c          --traditional
    -C          --copyright
    -d[file]        --dump-variables[=file]
    -D[file]        --debug[=file]
    -e 'program-text'   --source='program-text'
    -E file         --exec=file
    -g          --gen-pot
    -h          --help
    -i includefile      --include=includefile
    -l library      --load=library
    -L[fatal|invalid|no-ext]    --lint[=fatal|invalid|no-ext]
    -M          --bignum
    -N          --use-lc-numeric
    -n          --non-decimal-data
    -o[file]        --pretty-print[=file]
    -O          --optimize
    -p[file]        --profile[=file]
    -P          --posix
    -r          --re-interval
    -s          --no-optimize
    -S          --sandbox
    -t          --lint-old
    -V          --version

To report bugs, see node `Bugs' in `gawk.info'
which is section `Reporting Problems and Bugs' in the
printed version.  This same information may be found at
https://www.gnu.org/software/gawk/manual/html_node/Bugs.html.
PLEASE do NOT try to report bugs by posting in comp.lang.awk,
or by using a web forum such as Stack Overflow.

gawk is a pattern scanning and processing language.
By default it reads standard input and writes standard output.

Examples:
    gawk '{ sum += $1 }; END { print sum }' file
    gawk -F: '{ print $1 }' /etc/passwd


awk
  • 1 个回答
  • 38 Views
Martin Hope
John Smith
Asked: 2023-10-12 16:18:59 +0800 CST

为什么这个脚本将同名文件视为相同文件?

  • 6
#!/usr/bin/bash

install_wm() {
    echo "$(dirname "$0")"
    cd "$(dirname "$0")" && pwd
    mkdir -p /root/.config && cd /root/.config &&
    git clone https://git.suckless.org/dwm && cd dwm && pwd &&
    diff "$(dirname "$0")/config.def.h" /root/.config/dwm
    cp -f "$(dirname "$0")/config.def.h" /root/.config/dwm &&
}

install_wm

root当我运行这个脚本时

.
/home/jim/CS/SoftwareDevelopment/MySoftware/Bash/ubuntu-server-LTS
Cloning into 'dwm'...
remote: Enumerating objects: 6504, done.
remote: Counting objects: 100% (6504/6504), done.
remote: Compressing objects: 100% (3216/3216), done.
remote: Total 6504 (delta 3733), reused 5933 (delta 3287), pack-reused 0
Receiving objects: 100% (6504/6504), 6.18 MiB | 8.86 MiB/s, done.
Resolving deltas: 100% (3733/3733), done.
/root/.config/dwm
cp: './config.def.h' and '/root/.config/dwm/config.def.h' are the same file

我将此脚本运行为root. $(dirname "$0")/config.def.h是我的配置文件,它与克隆的存储库中的配置文件具有不同的内容,并且与脚本位于同一目录中。cp './config.def.h' and '/root/.config/dwm/config.def.h' are the same file如果文件只有相同的名称而不是内容,为什么我会得到?此外,当我diff在脚本之外手动运行这两个文件时,我得到的输出显示了它们之间的差异:

22,23c22,23
< static const char *tags[] = { "Brave", "ffplay", "Geany", "Terminal", "5", "6", "7", "8" };
< //https://wiki.gentoo.org/wiki/Dwm#Assigning_applications_to_window_tags
---
> static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
> 
30,34c30,31
<   { "brave-browser", NULL,  NULL,       0,            1,           -1 },
<   { "ffplay",  NULL,       NULL,       1 << 1,       0,           -1 },
<   { "geany",  NULL,       NULL,       1 << 2,       0,           -1 },
<   { "lxterminal",  NULL,       NULL,       1 << 3,       0,           -1 },
<   { "gnome-screenshot",  NULL,NULL,     1 << 4,       1,           -1 },
---
>   { "Gimp",     NULL,       NULL,       0,            1,           -1 },
>   { "Firefox",  NULL,       NULL,       1 << 8,       0,           -1 },
61,63c58
< /* commands 
< https://youtu.be/wRh8HQ4ICwE
< */
---
> /* commands */
66,71c61
< static const char *termcmd[]  = { "lxterminal", NULL };
< static const char *downv[]  = { "amixer", "set", "Master", "3+", NULL };
< static const char *upv[]  = { "amixer", "set", "Master", "3-", NULL };
< static const char *mute[]  = { "amixer", "set", "Master", "toogle", NULL };
< 
< 
---
> static const char *termcmd[]  = { "st", NULL };

diff而从我的脚本中运行时我没有得到任何输出。这里发生了什么?

bash
  • 1 个回答
  • 237 Views
Martin Hope
John Smith
Asked: 2023-10-09 04:39:45 +0800 CST

停止蓝牙服务也会将其关闭吗?

  • 5

在其他条件相同的情况下,三台计算机中哪一台(在执行各自的命令后)消耗的能量最多?哪个能量最少?

1. bluetoothctl power off

2. bluetoothctl power off && doas systemctl stop bluetooth

3. doas systemctl stop bluetooth

停止蓝牙服务也会将其关闭吗?

terminal
  • 1 个回答
  • 30 Views
Martin Hope
John Smith
Asked: 2023-08-28 17:10:35 +0800 CST

如何从数组数组中选择要循环的数组?

  • 8
#!/usr/bin/bash


ARGENT=("Nous devons économiser de l'argent."
"Je dois économiser de l'argent.")

BIENETRE=("Comment vas-tu?" "Tout va bien ?")

aoarrs=("${ARGENT}" "${BIENETRE}")

select arr in "${aoarrs[@]}"; do
  for el in "${arr[@]}"; do
    echo "$el"
  done
  break
done 

我希望此脚本将数组名称打印给用户ARGENT和BIENETRE,以便用户可以选择其中之一。用户输入后,脚本将打印所选数组的每个元素。我想从数组的数组 ( ) 中选择select一个数组来循环aoarrs。我想使用 select 的原因是因为在现实世界中,我的数组数组中可能不止两个数组。我怎样才能做到这一点?

bash
  • 4 个回答
  • 786 Views
Martin Hope
John Smith
Asked: 2023-08-22 16:20:17 +0800 CST

如何可靠地捕获此脚本中“ls”的输出?

  • 7

以下脚本play_movie.sh旨在自动选择一部电影(如果当前目录中只有一部电影)并使用ffplay. 否则,它的目的是向用户显示一系列电影并接受他们的输入(要播放的电影)。

#!/usr/bin/bash

output_a=$(ls -R *.[aA][vV][iI] 2>/dev/null)
output_m=$(ls -R *.[mM][kKpP][vV4]] 2>/dev/null)
output_v=$(ls -R *.[vV][oO][bB]] 2>/dev/null)
all_exts="${output_a}${output_m}${output_v}"
ln_cnt=$(echo "${all_exts}" | wc -l)

if [[ "$ln_cnt" -eq 1 ]]; then
  echo -e "Playing: ${all_exts}\n"
  ffplay -hide_banner -infbuf -fs -sn -ast a:0 "${all_exts}"
elif [[ "$ln_cnt" -gt 1 ]]; then
  printf "Select a file out of the list below"
  ls -R *.[aA][vV][iI] 2>/dev/null 
  ls -R *.[mM][kKpP][vV4] 2>/dev/null 
  ls -R *.[vV][oO][bB] 2>/dev/null
  read line; ffplay -hide_banner -infbuf -fs -sn -ast a:0 "$line"
fi

我对这个脚本的问题是:

  1. if即使当前目录中有很多电影,脚本也会执行语句的第一个分支。然后我明白了No such file or directory。
  2. 如果只有一部电影要播放,我会的No such file or directory。

我很难依赖ls过去的输出。是否可以修复此脚本而无需使用find?

ls
  • 2 个回答
  • 401 Views
Martin Hope
John Smith
Asked: 2023-08-10 16:01:23 +0800 CST

为什么我想在打印到标准输出时避免使用“printf”这种类似于回显的方式?[复制]

  • 5
这个问题在这里已经有了答案:
不给 printf 使用格式会带来安全后果吗? (2 个回答)
4 天前关闭。

当我试图了解如何工作时,我编写了以下脚本printf:

#!/usr/bin/bash

printf "Give me your three preferences.?
"
read p1
read p2
read p3
printf "%s\n" "${p1}" "${p2}" "${p3}"
printf "Just the same as this, \n"
printf "%s\n%s\n%s\n" "${p1}" "${p2}" "${p3}"
printf "I've found this way to be the easiest, ${p1}\n ${p2}\n ${p3}\n"

通过反复试验,我发现第三种方法是有效的 - 尽管没有指定这个学习资源。我printf最常使用这种方式,因为它echo类似于 -。是否存在这种打印值的方式stdout不起作用的变量情况或值?为什么我想避免这种使用方式printf?

bash
  • 2 个回答
  • 67 Views
Martin Hope
John Smith
Asked: 2023-04-12 16:21:12 +0800 CST

我如何从另一个交互式 Bash 脚本中获取 Bash 脚本?

  • 5

我有一个交互式 Bash 脚本conozcoArrays.sh,,

#!/usr/bin/bash

echo -e "\nGive me their phone number?\n"

read number

TOGOes=("$(find ~/chicas -maxdepth 1 -iname "*$number*" -type d -execdir echo {} + | sed "s;./;${HOME}/chicas/;g")" 
"$(find ~/chulos -maxdepth 1 -iname "*$number*" -type d -execdir echo {} + | sed "s;./;${HOME}/chulos/;g")"
"$(find ~/parejas -maxdepth 1 -iname "*$number*" -type d -execdir echo {} + | sed "s;./;${HOME}/parejas/;g")"
)

for togo in "${TOGOes[@]}"
do
  if [[ $togo != "" ]]; then
    echo $togo
    export togo && cd $togo && return 0
  else
    echo "Haven't found her in my directories." && cd ~/chicas
  fi
done

在我的目录中搜索关键字,如果找到任何内容,它会更改到该目录。出于这个原因,我通常会启动它采购它,就像这样 . ~/CS/SoftwareDevelopment/MySoftware/Bash/pasion/conozcoArrays.sh

我还有另一个 Bash 脚本,todo.sh它引用了“conozcoArrays.sh”:

#!/usr/bin/bash

ita='\e[3m'
end='\e[0m'

echo -e "1. La conozco?
2. Search through websites for a given phone number and create a dossier.
3. {ita}escort-scraper.py{end}"

read ch

if [[ "${ch}" == '1' ]]; then
  . ~/CS/SoftwareDevelopment/MySoftware/Bash/pasion/conozcoArrays.sh
elif [[ "${ch}" == '2' ]]; then
  "${HOME}/CS/SoftwareDevelopment/MySoftware/Python/escorts/search-no.py"
elif [[ "${ch}" == '3' ]]; then
  "${HOME}/CS/SoftwareDevelopment/MySoftware/Python/escorts/escort-scraper.py"
fi

问题是,当我输入1 conozcoArrays.sh 未被评估时,它已启动但似乎没有来源 - 我希望在脚本todo.sh完成后位于不同的目录中,但我没有。我如何conozcoArrays.sh从另一个交互式脚本中获取资源?

bash
  • 1 个回答
  • 42 Views
Martin Hope
John Smith
Asked: 2023-02-26 23:11:55 +0800 CST

为什么这个脚本不像手动运行时那样从 crontab 成功?

  • 7

此脚本在执行时有效doas ./backup_cron_root.sh

#!/usr/bin/bash

/usr/bin/crontab -l> "/tmp/cron.$(whoami).$(hostname)" && /bin/date>>"/tmp/cron.$(whoami).$(hostname)" &&
/usr/bin/doas -u joanna /usr/bin/cp -f "/tmp/cron.$(whoami).$(hostname)" "/home/joanna/pCloudDrive/backups" &&
/usr/bin/rm "/tmp/cron.$(whoami).$(hostname)"

./backup_cron_root.sh脚本的名称在哪里。当同一个脚本被安排为 cronjob 时 doas crontab -e,* * * * * /home/joanna/backup_cron_root.sh >/tmp/cronjob.log 2>&1 它创建了/tmp/cron.root.joanna-ONE-AMD-M4它所拥有的root 但由于某种原因它没有成功地将它复制到/home/joanna/pCloudDrive/backups. 为什么这样?为什么这个脚本不像手动运行时那样从 crontab 成功?

我的内容/etc/doas.conf是

permit joanna as root
permit root as joanna

以下是我的尾巴grep CRON /var/log/syslog:


Feb 26 17:17:01 joanna-ONE-AMD-M4 CRON[747796]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 26 17:17:01 joanna-ONE-AMD-M4 CRON[747797]: (root) CMD (/home/joanna/backup_cron_root.sh)
Feb 26 17:17:01 joanna-ONE-AMD-M4 CRON[747792]: (CRON) info (No MTA installed, discarding output)
Feb 26 17:17:01 joanna-ONE-AMD-M4 CRON[747791]: (CRON) info (No MTA installed, discarding output)
Feb 26 17:17:01 joanna-ONE-AMD-M4 CRON[747794]: (CRON) info (No MTA installed, discarding output)
Feb 26 17:17:01 joanna-ONE-AMD-M4 CRON[747793]: (CRON) info (No MTA installed, discarding output)
Feb 26 17:17:22 joanna-ONE-AMD-M4 CRON[747795]: (CRON) info (No MTA installed, discarding output)
Feb 26 17:18:01 joanna-ONE-AMD-M4 CRON[751555]: (root) CMD (/home/joanna/backup_cron_root.sh)
Feb 26 17:18:01 joanna-ONE-AMD-M4 CRON[751551]: (CRON) info (No MTA installed, discarding output)
Feb 26 17:18:01 joanna-ONE-AMD-M4 CRON[751550]: (CRON) info (No MTA installed, discarding output)
Feb 26 17:18:01 joanna-ONE-AMD-M4 CRON[751553]: (CRON) info (No MTA installed, discarding output)
Feb 26 17:18:01 joanna-ONE-AMD-M4 CRON[751552]: (CRON) info (No MTA installed, discarding output)
Feb 26 17:18:22 joanna-ONE-AMD-M4 CRON[751554]: (CRON) info (No MTA installed, discarding output)

的内容/tmp/cronjob.log是

doas: Authentication failed
cron
  • 1 个回答
  • 95 Views
Martin Hope
John Smith
Asked: 2023-02-22 18:36:40 +0800 CST

为什么从 Python 的运行中转义双引号(使用 shell=True)与在 Bash 中不同?

  • 8

我需要使用我的 Python 脚本生成echo并调用 JSON 配置文件。tee

通过反复试验,我发现我必须使用单引号。然而,我不理解我在使用 Python 的run(). 以下代码打印我的问题:

#!/usr/bin/env python3

from subprocess import run

conf_file="""{
"alt-speed-down": 50,
}"""
print("Question 1. It does not work with double quotes. Why?")
run(f"""echo "{conf_file}" """, shell=True)
print("It works with single quotes.")
run(f"""echo '{conf_file}'""", shell=True)
conf_file="""{
\"alt-speed-down\": 50,
}"""
print("""Question 2. It does not work with double quotes, even when I escape the quotes.
Whereas when I type in my shell: 
echo "\"This is a quoted string.\"" 
it works. Why? 
""")
run(f"""echo "{conf_file}" """, shell=True)
print("""Question 3. It works with single quotes, even with escaped quotes. 
whearas when I type in my shell:
echo '\"this is quoted\"' 
I get the backslashes printed. Why aren't
the backslashes printed when called with Python's run()?""")
run(f"""echo '{conf_file}'""", shell=True)

我使用 Bash 作为我的 shell。与 Python 的运行相比,为什么从我的 Bash shell 转义双引号会有所不同。我不是通过指定 shell=Truein来访问我的 Bash shell 吗run()?

PS 我知道用json模块生成 JSON 是一种方法,但在我的例子中,它主要是从我的备份配置文件中复制现有的 JSON。我想避免在我的脚本中将此类 JSON 文件读入字符串 - 该脚本旨在在新重新安装的操作系统上运行,此类备份最初不可用。这就是为什么我需要在我的 Python 字符串中有很多字符串变量来存储这样的 JSON 配置文件

bash
  • 1 个回答
  • 181 Views
Martin Hope
John Smith
Asked: 2022-07-01 02:50:13 +0800 CST

在基于 Linux 的系统上启动进程所需的最小内存量是多少?

  • 3

两种语言的例程都很便宜:goroutine 每个 2KB,而 Elixir 进程每个 0.5KB。

我知道在BEAM中启动一个进程需要 0.5KB 的内存。这在Elixir和 Erlang的情况下是如此轻量级,而在Go的情况下在较小程度上似乎是使用这些运行时的优势,与其他依赖于它们自己的不那么便宜的进程和线程或依赖的语言相比底层 OS的进程和线程(据说也需要更多内存)。

我想知道在基于 Linux 的系统上启动进程需要多少内存。我知道内存使用情况取决于进程在做什么。但我假设只是启动一个什么都不做的进程会产生内存成本)。那费用是多少?
我在哪里可以阅读更多关于它的信息?有没有我可以检查的文件/命令?

memory process
  • 1 个回答
  • 125 Views
Martin Hope
John Smith
Asked: 2022-05-28 03:50:11 +0800 CST

我如何并行执行这个嵌套的 for 循环?

  • 0
#!/usr/bin/bash

TARGETS=(
"81.176.235.2"
"81.176.70.2" 
"78.41.109.7" 
)

myIPs=(
"185.164.100.1"
"185.164.100.2"
"185.164.100.3"
"185.164.100.4"
"185.164.100.5"
)

for t in "${TARGETS[@]}"
  do 
    for a in "${myIPs[@]}"
    do 
      echo "${a} ${t} -p 80" >>log 2>&1 &
      echo "${a} ${t} -p 443" >>log 2>&1 &
      wait
    done 
    
done

我希望这段代码从每个 IP 的 echo 命令开始,TARGETS以并行执行它们。同时,该脚本并不意味着同时对多个地址执行回显命令myIPs,因此我wait在内部循环中进行了介绍。我想为echo每个目标在. 换句话说,我想做到这一点(但遗憾的是它不起作用):80443TARGETS

for t in "${TARGETS[@]}"
do &
  for a in "${myIPs[@]}"
  do 
    echo "${a} ${t} -p 80" >>log 2>&1 &
    echo "${a} ${t} -p 443" >>log 2>&1 &
    wait
  done 

done
wait 

然而,因为它会增加我的平均负载太多,我不想要这个::

for t in "${TARGETS[@]}"
do
  for a in "${myIPs[@]}"
  do 
    echo "${a} ${t} -p 80" >>log 2>&1 &
    echo "${a} ${t} -p 443" >>log 2>&1 &
  done 
done
wait 

我怎样才能实现我的目标?

PS 这只是一个更复杂的脚本的片段。我想隔离相关问题,因此使用echo而不是网络命令之一。

bash for
  • 2 个回答
  • 115 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve