0

I am trying to execute cqlsh inside bash script. My script is below. When ı try to execute sh file, it returns cql command not found

#!/bin/bash

set -x

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

cqlsh -e "SELECT * FROM msg.msg_log limit 1;" > /home/yunus/sh/cqlshcontrol.txt

error1=$( more /home/yunus/sh/cqlshcontrol.txt | wc -l )

if [ $error1 -lt 1 ]; then

curl -S -X POST --data "payload={\"text\": \" Cqlsh not responding, Connection Problem   \",\"username\":\"Elevate Cassandra1\",\"icon_emoji\":\"${SLACK_ICON}\"}" https://hooks.slack.com/services/

fi
getaffe
  • 41
  • 1
  • 7

1 Answers1

1

some suggestions

  1. use [[/]] over [/].
  2. the return value of $() is not an error value and should be named lines or something more meaningful. The lack of another error variable in the code makes the appended number (the 1 in error1) seem even odder.
  3. There's no reason to use more or pipe inside of that subshell. Just run wc -l on your file.
  4. Are you sure cqlsh is in the PATH? Try which cqlsh to find it.
  5. wc will never return a negative value so comparing for equality with zero would be clear and cover just as many potential cases.

otherwise

If that doesn't get you out of your confusion please show the output when you try to run it.

chicks
  • 2,393
  • 3
  • 24
  • 40