bash

Schedule Python Script in Bash?

时间秒杀一切 提交于 2021-02-10 05:37:54
问题 I am new to scheduling python scripts and need to start a script so it can run for a day or two. I am not allowed to use cron in my environment so am using this bash script. What is a simple test I can do to make sure the python file runs? How would I know that my file ran? And also, if it throws an error, how can I make sure I am notified? Any help would be appreciated. #!/usr/bin/bash while true do DATE="$(date +'%d')" MONTH="$(date +'%m')" YEAR="$(date +'%Y')" HOUR="$(date +'%H')" MINUTE="

Bash - find exec return value

大兔子大兔子 提交于 2021-02-10 04:51:18
问题 I need a way to tell if grep does find something, and ideally pass that return value to an if statement. Let's say I have a tmp folder (current folder), in that there are several files and sub-folders. I want to search all files named abc for a pattern xyz . The search is assumed to be successful if it finds any occurrence of xyz (it does not matter how many times xyz is found). The search fails if no occurrence of xyz is found. In bash, it can be done like this: find . -name "abc" -exec grep

how to trap errors inside the if statement

丶灬走出姿态 提交于 2021-02-10 03:12:30
问题 Running the following code: #!/bin/bash set -o pipefail set -o errtrace set -o nounset set -o errexit function err_handler () { local error_code="$?" echo "TRAP!" echo "error code: $error_code" exit } trap err_handler ERR echo "wrong command in if statement" if xsxsxsxs then echo "if result is true" else echo "if result is false" fi echo -e "\nwrong command directly" xsxsxsxs exit produces the following output: wrong command in if statement trap.sh: line 21: xsxsxsxs: command not found if

how to trap errors inside the if statement

戏子无情 提交于 2021-02-10 03:06:45
问题 Running the following code: #!/bin/bash set -o pipefail set -o errtrace set -o nounset set -o errexit function err_handler () { local error_code="$?" echo "TRAP!" echo "error code: $error_code" exit } trap err_handler ERR echo "wrong command in if statement" if xsxsxsxs then echo "if result is true" else echo "if result is false" fi echo -e "\nwrong command directly" xsxsxsxs exit produces the following output: wrong command in if statement trap.sh: line 21: xsxsxsxs: command not found if

9月19日任务

自闭症网瘾萝莉.ら 提交于 2021-02-09 20:33:25
2.27 Linux和windows互传文件(后期使用xftp方便) 注:putty不支持。 Xshell或者secureCRT支持,如果卡死,说明数据没有传输完成,或者说传输出现异常,不用重启,重新打开一个终端即可。 安装包:[root@ys-210 ~]# yum install -y lrzsz linux传输到windows上 命令sz [root@ys-210 789]# sz linux.txt windows传输至linux 命令rz (r表示remote远程的意思) [root@ys-210 789]# rz 3.1 用户配置文件和密码配置文件 用户账号被锁了,怎么解锁 r oot用户去解锁 解锁是passwd -u 用户配置文件,创建用户都会在此配置文件增加一行 [root@ys-210 ~]# ls /etc/passwd 配置文件规则:每个用户一行,由冒号分隔为7段,第一行是超级管理员root,下面开始是系统自己创建的,系统生成时产生,在后面是管理员创建或者普通用户创建 root:x:0:0:root:/root:/bin/bash ys:x:1000:1000::/home/ys:/bin/bash 用户名: 早期是用户密码(现密码存储路径[root@ys-210 ~]# ls /etc/shadow) :UID(每个用户有个ID):GID(组ID)

generate JSON out of command line arguments

扶醉桌前 提交于 2021-02-09 17:51:22
问题 I want to create JSON output with jq that looks like this: { "records": [ { "id": "1234", "song": "Yesterday", "artist": "The Beatles" } ] } I assumed I have to twiddle with the "filter" of jq whose concept I don't fully get after reading the doc. This is what I got so far: $ jq --arg id 1234 \ --arg song Yesterday \ --arg artist "The Beatles" \ '.' \ <<<'{ "records" : [{ "id":"$id", "song":"$song", "artist":"$artist" }] }' which prints { "records": [ { "id" : "$id", "song" : "$song", "artist

generate JSON out of command line arguments

有些话、适合烂在心里 提交于 2021-02-09 17:51:16
问题 I want to create JSON output with jq that looks like this: { "records": [ { "id": "1234", "song": "Yesterday", "artist": "The Beatles" } ] } I assumed I have to twiddle with the "filter" of jq whose concept I don't fully get after reading the doc. This is what I got so far: $ jq --arg id 1234 \ --arg song Yesterday \ --arg artist "The Beatles" \ '.' \ <<<'{ "records" : [{ "id":"$id", "song":"$song", "artist":"$artist" }] }' which prints { "records": [ { "id" : "$id", "song" : "$song", "artist

generate JSON out of command line arguments

亡梦爱人 提交于 2021-02-09 17:50:38
问题 I want to create JSON output with jq that looks like this: { "records": [ { "id": "1234", "song": "Yesterday", "artist": "The Beatles" } ] } I assumed I have to twiddle with the "filter" of jq whose concept I don't fully get after reading the doc. This is what I got so far: $ jq --arg id 1234 \ --arg song Yesterday \ --arg artist "The Beatles" \ '.' \ <<<'{ "records" : [{ "id":"$id", "song":"$song", "artist":"$artist" }] }' which prints { "records": [ { "id" : "$id", "song" : "$song", "artist

generate JSON out of command line arguments

泄露秘密 提交于 2021-02-09 17:49:24
问题 I want to create JSON output with jq that looks like this: { "records": [ { "id": "1234", "song": "Yesterday", "artist": "The Beatles" } ] } I assumed I have to twiddle with the "filter" of jq whose concept I don't fully get after reading the doc. This is what I got so far: $ jq --arg id 1234 \ --arg song Yesterday \ --arg artist "The Beatles" \ '.' \ <<<'{ "records" : [{ "id":"$id", "song":"$song", "artist":"$artist" }] }' which prints { "records": [ { "id" : "$id", "song" : "$song", "artist

generate JSON out of command line arguments

余生颓废 提交于 2021-02-09 17:47:53
问题 I want to create JSON output with jq that looks like this: { "records": [ { "id": "1234", "song": "Yesterday", "artist": "The Beatles" } ] } I assumed I have to twiddle with the "filter" of jq whose concept I don't fully get after reading the doc. This is what I got so far: $ jq --arg id 1234 \ --arg song Yesterday \ --arg artist "The Beatles" \ '.' \ <<<'{ "records" : [{ "id":"$id", "song":"$song", "artist":"$artist" }] }' which prints { "records": [ { "id" : "$id", "song" : "$song", "artist