sh

Inline if shell script

戏子无情 提交于 2020-05-09 20:07:20
问题 Is it possible to execute shell script in command line like this : counter=`ps -ef | grep -c "myApplication"`; if [ $counter -eq 1 ] then; echo "true"; > Above example is not working I get only > character not the result I'm trying to get, that is "true" When I execute ps -ef | grep -c "myApplication I get 1 output. Is it possible to create result from single line in a script ? thank you 回答1: It doesn't work because you missed out fi to end your if statement. counter=`ps -ef | grep -c

Execute a shell script everyday at specific time [duplicate]

假装没事ソ 提交于 2020-05-09 17:52:32
问题 This question already has answers here : How to write a cron that will run a script every day at midnight? (6 answers) Closed 4 years ago . I have a simple shell script that just checks the contents of a directory and if anything was added during the day makes a copy of it to a backup folder. I'd like to execute this script at the end of each day (let's assume at 23:55). The system(Debian) which this scripts reside on it, is always on (kind of server) How can I do that? 回答1: You want to edit

Compare two text files and print the difference against key in bash shell script

微笑、不失礼 提交于 2020-05-09 17:28:30
问题 Shell script, bash, have 2 large files around 1.2 GB data, with key and values, I need to compare both files based on the key and store difference in the value in the third file, File 2 will always be a subset of File 1, just need to find values( against key ) which are not present in file 2 and unique ones in File 1. File 1: test1 marco;polo;angus test2 mike;zen;liza test3 tom;harry;alan test4 bob;june;janet 1332239_44557576_CONTI Lased & Micro kjd $353.50_30062020_lsdf3_no-rule 343323H

Compare two text files and print the difference against key in bash shell script

巧了我就是萌 提交于 2020-05-09 17:28:25
问题 Shell script, bash, have 2 large files around 1.2 GB data, with key and values, I need to compare both files based on the key and store difference in the value in the third file, File 2 will always be a subset of File 1, just need to find values( against key ) which are not present in file 2 and unique ones in File 1. File 1: test1 marco;polo;angus test2 mike;zen;liza test3 tom;harry;alan test4 bob;june;janet 1332239_44557576_CONTI Lased & Micro kjd $353.50_30062020_lsdf3_no-rule 343323H

Find and Extract value after specific String from a file using bash shell script?

一笑奈何 提交于 2020-04-30 06:37:06
问题 I have a file which contains below details : file.txt +----------------------------------------------------+ | createtab_stmt | +----------------------------------------------------+ | CREATE EXTERNAL TABLE `dv.par_kst`( | | `col1` string, | | `col2` string, | | `col3` int, | | `col4` int, | | `col5` string, | | `col6` float, | | `col7` int, | | `col8` string, | | `col9` string, | | `col10` int, | | `col11` int, | | `col12` string, | | `col13` float, | | `col14` string, | | `col15` string) |

SQL Query that Create CSV file with Timestamp on it

一笑奈何 提交于 2020-04-18 06:14:09
问题 I created This shell script below, which fetches data from MySQL and create output as csv file. but I want to create this csv with a timestamp. so I just want filename to be like this result_ddmmyy.csv Is there any way to do this from script or from SQL query. #!/usr/bin/bash #scirpt to connect with db master_db_user='root' master_db_passwd='123' master_db_port='3306' master_db_host='localhost' master_db_name='sagar_tb' #Preparing script #MySql Command to connect to a database mysql -u$master

How to put environment variable in Array?

南楼画角 提交于 2020-04-18 06:10:13
问题 DIR1, DIR2, .... DIRN are coming from environment variables that contains some directory path. example export DIR1="/users/abcd" export DIR2="/users/abcd/xyz" . . . How do i know that how many DIR_ is in environment variable and put all these in the following array arr=(DIR1 DIR2 ... . . DIRN) i=0 while [ $i -lt ${#arr[@]} ] do cd ${arr[$i]} i=`expr $i + 1` done 回答1: For the cases when environment variables may contain newlines in their values you can use this script that uses gnu versions of

How to put environment variable in Array?

梦想与她 提交于 2020-04-18 06:10:08
问题 DIR1, DIR2, .... DIRN are coming from environment variables that contains some directory path. example export DIR1="/users/abcd" export DIR2="/users/abcd/xyz" . . . How do i know that how many DIR_ is in environment variable and put all these in the following array arr=(DIR1 DIR2 ... . . DIRN) i=0 while [ $i -lt ${#arr[@]} ] do cd ${arr[$i]} i=`expr $i + 1` done 回答1: For the cases when environment variables may contain newlines in their values you can use this script that uses gnu versions of

Passing a complex shell script via docker exec sh -c “…”

痴心易碎 提交于 2020-04-17 22:40:45
问题 I have a script that works fine in sh on a linux host as well as inside an alpine container. But when I try executing that using docker exec <containerID> sh -c "<script>" it misbehaves. The script's function is to output stuff similar to ps. systick=$(getconf CLK_TCK); for c in /proc/*/cmdline; do d=$(dirname $c); name=$(grep Name: $d/status); pid=$(basename $d); uid=$(grep Uid: $d/status); uid=$(echo ${uid#Uid:} | xargs); uid=${uid%% *}; user=$(grep :$uid:[0-9] /etc/passwd); user=${user%%:*

Terminal error: zsh: permission denied: ./startup.sh

被刻印的时光 ゝ 提交于 2020-03-15 20:54:17
问题 I am running a command ./startup.sh nginx:start and I am getting this error message zsh: permission denied: ./startup.sh why could this be happening? 回答1: Be sure to give it the execution permission. cd ~/the/script/folder chmod +x ./startup.sh 回答2: Alternatively you can use bash: bash startup.sh Then you don't need execution permission. In MacOS Catalina, Apple has replaced bash with zsh as default shell. This can mean, that they intend to remove bash in the future, so this might not be an