1. C

    Country and External IP Bash script

    I created a script based on what I could find on the INTERNET and some bash tutorials, that will show me my external IP and the country it's located in. # Script looks like this: #!/bin/bash wanip=$(dig +short; echo "$wanip" > /root/Documents/filewanip...
  2. J

    Select a jar file in maven project

    I have a jar file in my target directory of Jenkins Maven project. PROJ-0.0.2-SNAPSHOT.jar. There is another file called, PROJ-0.0.2-SNAPSHOT.jar.original I want to select only PROJ-0.0.2-SNAPSHOT.jar file. For that I used below command. ls target | grep \.jar$ I got the output as my...
  3. E

    Am I using the correct syntax for my shell script? [duplicate]

    I wrote a shell script that gets a value from a file and based on that value I want to echo a particular message. My console keeps on saying that there is an error on line 7 and 9. Any suggestions on how to fix it will be greatly appreciated. export...
  4. T

    Bash script to ensure only one instance of a script running & others waiting

    I have a bash script which invokes another is invoked only from I can have only one instance of executing at a time. If multiple invocations of is made then should make all the caller's wait if is already running...
  5. J

    Pass variable as options to curl in shell script linux [duplicate]

    I'm trying to update some info of a web site using curl through a script but it's not working well, this is the code i have: CURL_STD_OPTS="-k --header 'Content-Type: application/json' --header 'Accept: application/json' curl "$CURL_STD_OPTS" -X POST --data '{ "actual": '"$BAL"' }'...
  6. D

    Bash function doesn't work for remote ssh command execution although interactive shell function fine

    I define a function in .bash_aliases file and include it in my .bashrc file. My .bash_aliases file: function dmidecode() { if [[ $1 == -t && $2 == 1 ]]; then cat ~/some_file else command dmidecode "$@" fi } The function is: when someone...
  7. D

    How to append values to an array in Bash by adding one element to the previous entry?

    I have a list of numbers 1 2 3 4 5 that I am trying to organize into an array where the values are in a sequence where the current value is the summation of the previous values in the array (like this): 1 3 6 10 15. My current code is as follows: array=() for n in `seq 1 5` do if [ $n -eq 1...
  8. P

    How to stop sed from inserting newline?

    I want to stop sed from adding a newline with the i editing command: > `echo "hello" | sed 'i TEST'` TEST hello The result I want is: TESThello
  9. J

    Modification of configuration file using sed

    mongod.conf file # mongod.conf # for documentation of all options, see: # # Where and how to store data. storage: dbPath: /var/lib/mongodb journal: enabled: true # engine: # mmapv1: # wiredTiger: # where to...
  10. D

    Kill multiple process at once works only manually not from inside script

    I'm trying to kill multiple process at the same time. Im using this simple for loop to kill the process by PID number. for i in $(ps -ejH | grep omn_bdxtrc|awk '{print $1}'); do kill ${i}; done The loop works fine if I enter it manually in the terminal. but if I want to us it from inside an...
  11. L

    Prevent race condition when creating lock file

    My script must not be run more than once concurrently. So it creates a lock file, and deletes it before exiting. It checks that lock file doesn't exist before starting its work. A very common approach to locking is something like this: function setupLockFile() { if (set -o noclobber; echo...
  12. D

    Call the aliased command inside a bash script

    I want to create an alias to a specific command with flags arc diff --preview I have created the following bash function arc(){ if [ "$1" = "diff" ] && [ "$2" = "--preview" ] ; then echo -n "Message example? (y/n)? " read answer if [ "$answer" != "${answer#[Yy]}" ] ;then arc...