-1

I am running a script in bash prompt/command line manually. How to pass arguments?

mem_utilization=`free -m | awk 'NR==2{printf "%.2f\n", $3*100/$2 }'`

Note:

I am new to scripting, that's the reason above code is incomplete. Please use any argument in the code. Let's say username and password are the arguments.

One can answer this question in the manual context.

(Just to give you a brief, this is what I am trying to do. I like to know this and do the same when running the code through SSH in exec mode (or) bash prompt (or) command line (or) python code in python prompt.)

mem_utilization=`free -m | awk 'NR==2{printf "%.2f\n", $3*100/$2 }'`

Note:

Use % symbol as an argument and attach at the end.

mem_utilization=80%
Allan
  • 12,117
  • 3
  • 27
  • 51
Pavan608
  • 29
  • 1
  • 4

1 Answers1

0

For the first part I am not quite sure what you want to do: using your awk-syntax you can append your % with:

mem_utilization=$(free -m | awk 'NR==2{printf "%.2f\n", $3*100/$2 }')
mem_utilization=$mem_utilization'%'
echo ${mem_utilization}

you can place this in a shell script to run over SSH with something like

ssh user@pc123456 'bash -s' < local_script.sh

and for the fact that you want to pass arguments to python promts via ssh: this works just like any other time: use argparse and give the arguments with "path_to_script" -"name of your argument1" ... --"name of your argumentn"

The fact that you want to use a password as an argument is something you have to consider carefully: You could use sshpass. But then PLEASE DO NOT WRITE IT INTO THE SCRIPT. Instead use read to enter the password one time. (compare to this discussion: Automatically enter SSH password with script)

Arbor Chaos
  • 149
  • 6