小编Nun*_*uno的帖子

如何从我的 bash 脚本创建日志文件

如何从 bash 脚本创建日志文件?

我留下的脚本没有选项,我想知道的是如何注册正在使用的脚本并创建一个单独的.log文件。

脚本:

#!/bin/bash
trash=~/TRASH
if [ ! -e $trash ]; then
  mkdir $trash
elif [ ! -d $trash ]; then
  echo "$0: error: $trash is not a directory"; exit 1
fi

while getopts "hr:t:s:u:" options; do
case $options in

#ALL THE OPTIONS AREN'T HERE FOR THE PURPOSE OF KEEPING IT SHORTER

shift $((OPTIND-1))

while [ $# -gt 0 ]; do
  if [ ! -e $1 ]; then
    echo "$0: error: tried to delete file that …
Run Code Online (Sandbox Code Playgroud)

bash shell tee io-redirection

2
推荐指数
1
解决办法
2万
查看次数

Pickle 数据被截断

在尝试将列表发送到客户端进程时,我对其进行了pickle,但是当我在客户端收到此列表时,它总是给出错误pickle data was truncated,并且我不知道如何修复它。

SV

def handle_client(connection):
    connection.send(str.encode('welcome to sv'))
    stock = random.sample(output, 1)
    order = pickle.dumps(stock)
    while True:
        data = connection.recv(2048)
        if not data:
            break
    if data.decode('utf-8') == 'wanna trade!':
        print("trade order received")
        tcp.send(order)
    reply = connection.recv(2048)
    if reply.decode('utf-8') == 'Y':
       tcp.send(order)
       output.remove(order)
    elif reply.decode('utf-8') == 'N':
        print("doesn't wish to buy.")
    connection.close()

Run Code Online (Sandbox Code Playgroud)

客户

while True:
    Cliente.send(str.encode('wanna trade!'))
    recv = Cliente.recv(2048)
    if not recv:
        break
    if recv:
        Response = pickle.loads(recv)
        print(Response)
        Check = input('Y/N: ')
        Cliente.send(str.encode(Check))
    recv2 = Cliente.recv(2048)
    if …
Run Code Online (Sandbox Code Playgroud)

python

2
推荐指数
1
解决办法
8632
查看次数

标签 统计

bash ×1

io-redirection ×1

python ×1

shell ×1

tee ×1