ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
ssh_shell_request is not a built-in function for Python, and you've not shared the code, so nobody here knows how you're executing those two scripts - my guess is they are NOT being executed as Bash scripts but you're using Bash-specific features.
I haven't actually looked at either script to determine this - too much effort with them formatted as a single line. Python (like Bash) supports multiline strings if you delimit them with """ - you should be making use of that functionality.
(Similarly, the formatting of your Bash script is all over the place - such an easy thing to fix and makes a huge difference to readability.)
Once you've fixed the formatting, running the scripts through ShellCheck will almost certainly highlight the issues.
Thanks Guys, main script is already executing without errors, How do i fix the below ones ?
Code:
$ shellcheck myscript
Line 2:
command="DATE_TODAY=$"(date +%Y-%m-%d); EXPIRED_DATE=$(cat /home/Admin/user_expiry.txt); DATE_TODAY_SEC=$(date --date $DATE_TODAY +'%s); EXPIRED_DATE_SEC=$(date --date "$EXPIRED_DATE +'%s'); DAYS_EXPIRED=$(expr $EXPIRED_DATE_SEC - 864000); if [ $DATE_TODAY_SEC -ge $DAYS_EXPIRED ]; then echo 'EXPIRED' ; else echo 'HEALTHY' ; fi"
^-- SC2034 (warning): command appears unused. Verify use (or export if used externally).
^-- SC1036 (error): '(' is invalid here. Did you forget to escape it?
^-- SC1088 (error): Parsing stopped here. Invalid use of parentheses?
Code:
$ shellcheck myscript
Line 2:
command=LOG='/home/Admin/user_expiry.txt' ; while read LIST ; do DATE=$(echo "$LIST | awk '{print $3}') ; CHECK=$(echo $DATE | grep -v \":\") ; if [[ ! -z '$CHECK' ]]; then if [[ \"$CHECK\" != \"HEALTHY\" ]] ; then if [[ $DATE -le 10 ]] ; then echo \"EXPIRED\" ; else echo \"HEALTHY\" ; fi ; else echo \"HEALTHY\" ; fi ; else echo \"EXPIRED\" ; fi ; done < $LOG"
>> ^-- SC1009 (info): The mentioned syntax error was in this variable assignment.
>> ^-- SC1073 (error): Couldn't parse this command expansion. Fix to allow more checks.
Line 3:
RESULTS['Scriptuser_expired_critical']=[(0,ssh_shell_request(conn,command))]
^-- SC1036 (error): '(' is invalid here. Did you forget to escape it?
^-- SC1072 (error): Expected end of $(..) expression. Fix any mentioned problems and try again.
Also, the log file name in your second Python script may be wrong. Judging by your main Bash script, you're generating two log files: 1) user_expiry.txt which only contains one value, password expiration date for a user, and 2) all_user_expiry.txt that contains two columns of data, user email and password age, for multiple users.
I guess that in your second Python script, you'd want to evaluate all_user_expiry.txt rather than user_expiry.txt. That said,
Code:
if [[ $DATE -le 10 ]]; then echo 'EXPIRED';...
doesn't make sense in either case.
The main script makes a strange impression. There's a striking contrast between a competent use of SQL and a helpless Bash code in the same script. Almost as if those parts were written by different persons.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.