I decided to state the situation in more detail.

There is a bash script that does all sorts of calculations, and defines variables, which will then be set as parameters for a python script.

B4_random.sh

#!/bin/bash clear #Укажи имя проекта Proekt="B4" #Укажи файл с диапазонами в формате /32 IP="IP_1" #Укажи колличество рандомных диапазанов IP_Random="5" #Сколько логинов ты хочешь сгенирировать Logins_Random="1" #Укажем имена пользывателей которое обязательно будут задействованы #Standart_Logins="admin" #Сколько паролей ты хочешь сгенирировать Passwords_Random="1" #Какой протокол будем брутить Target="-b rdp" #Сколько потоков ты хочешь задействовать Potok="-n 2000" #Удаляем дубликаты диапазонов rm ~/Yandex.Disk/Задачи/_Диапазоны/crow/$Proekt #Генерируем диапазоны cat | shuf -n $IP_Random ~/Yandex.Disk/Задачи/_Диапазоны/crow/$IP >> ~/Yandex.Disk/Задачи/_Диапазоны/crow/$Proekt & #Удаляем дубликаты логинов rm ~/Yandex.Disk/Задачи/_Словари/logins/BOSS/$Proekt #Генерируем логины cat | shuf -n $Logins_Random ~/Yandex.Disk/Задачи/_Словари/logins/BOSS/LOGINS >> ~/Yandex.Disk/Задачи/_Словари/logins/BOSS/$Proekt & #Удаляем дубликаты паролей rm ~/Yandex.Disk/Задачи/_Словари/passwds/BOSS/$Proekt #Генерируем пароли cat | shuf -n $Passwords_Random ~/Yandex.Disk/Задачи/_Словари/passwds/BOSS/PASSWORDS >> ~/Yandex.Disk/Задачи/_Словари/passwds/BOSS/$Proekt & #Приступаем к бруту cd .. set -x python crowbar.py -v $Potok $Target -S ~/Yandex.Disk/Задачи/_Диапазоны/crow/$Proekt -U ~/Yandex.Disk/Задачи/_Словари/logins/BOSS/$Proekt -C ~/Yandex.Disk/Задачи/_Словари/passwds/BOSS/$Proekt -o ~/Yandex.Disk/Задачи/_Результат/$Proekt echo "OK !!!" 

when executing ./B4_random, set -x shows

 python crowbar.py -v -n 2000 -b rdp -S /home/user/Yandex.Disk/Задачи/_Диапазоны/crow/B4 -U /home/user/Yandex.Disk/Задачи/_Словари/logins/BOSS/B4 -C /home/user/Yandex.Disk/Задачи/_Словари/passwds/BOSS/B4 -o /home/user/Yandex.Disk/Задачи/_Результат/B4 

When you run the BASH script, the work of the script is not felt

 + python crowbar.py -v -n 2000 -b rdp -S /home/user/Yandex.Disk/Задачи/_Диапазоны/crow/B4 -U /home/user/Yandex.Disk/Задачи/_Словари/logins/BOSS/B4 -C /home/user/Yandex.Disk/Задачи/_Словари/passwds/BOSS/B4 -o /home/user/Yandex.Disk/Задачи/_Результат/B4 2016-01-14 17:26:09 START 2016-01-14 17:26:11 STOP No result is found ... + echo 'OK !!!' OK !!! 

But if I copy tracing set -x

 python crowbar.py -v -n 2000 -b rdp -S /home/user/Yandex.Disk/Задачи/_Диапазоны/crow/B4 -U /home/user/Yandex.Disk/Задачи/_Словари/logins/BOSS/B4 -C /home/user/Yandex.Disk/Задачи/_Словари/passwds/BOSS/B4 -o /home/user/Yandex.Disk/Задачи/_Результат/B4 

and perform, the output will be as follows:

 2016-01-14 17:37:43 START 2016-01-14 17:37:43 LOG-RDP: 54.152.173.150:3389 - fullered:Cedric721 2016-01-14 17:37:43 LOG-RDP: 108.186.32.92:3389 - fullered:Cedric721 2016-01-14 17:37:43 LOG-RDP: 72.8.145.120:3389 - fullered:Cedric721 2016-01-14 17:37:43 LOG-RDP: 128.122.7.35:3389 - fullered:Cedric721 2016-01-14 17:37:43 LOG-RDP: 71.42.203.61:3389 - fullered:Cedric721 2016-01-14 17:39:51 STOP No result is found ... 

How to make the BASH script display the report in the same detail? Or even make it work ...

  • 2
    not quite clear what the problem is, do you want the python to display the commands that it executed? but can he? - BOPOH
  • @BOPOH can of course and in great detail . But in most cases you should just write logging events in the program, example: log() - jfs
  • Are you sure that you see both stdout and stderr? The problem is that not all output is printed or that all output is printed, but only at the end? - jfs
  • @jfs, I'm talking about something else, I have a print (123) script - there is nothing more. Is it possible to specify a specific option to make the python show the operations that he performed, i.e. Will the screen show not only 123 , but also print (123) ? Judging by the question ( set - x does not help ... shows the full launch command ), the author is exactly what interests him. Those. if it cannot be done without any gestures (like that library), this will be the answer - BOPOH
  • Though, probably, I am mistaken and not the python script is of interest, but how the parameters that are passed to this script are obtained. But the author is silent something. It would be better to give an example of what is and what awaits - BOPOH

2 answers 2

This answer was relevant for the original version of the question.


the internal shell command set -x defined in the posix standard and causes the shell (in your case, bash ) to execute each command (actually, the lines in the shell script ) output the full text of the command to stderr , with already substituted variable values.

This internal shell command, naturally, does not (and cannot) have any effect on the python interpreter, which is launched from a shell script .

The difference in the behavior of your python script is probably caused by different sets of options and parameters that you pass to this script in one and in another case.

  • It can be done so that the bash script would do the calculations, then the result of these calculations would be inserted into the python script as parameters. Because it's about crowbar brutus, i need to see it being executed ... - 3amunyk
  • Maybe you can do this - in the question you wrote that this is what you do. - aleksandr barakin

I compare the arguments of the two calls (I have explicitly removed the same):

 python crowbar.py $Report $Potok $Target python crowbar.py -v -n 2000 -b rdp 

most likely, inside the $Report variable you pass the string -v , inside $Potok - the string -n 2000 , inside $Target - the string -b rdp .

and here, it is likely that either the specificity of the python program works (I have seen this in some cases), or the specifics of the crowbar.py script: the script “perceives” these strings not as options, but as parameters.

Perhaps, use of the eval command built into the shell can help:

 eval python ... 

update

if the command and arguments do not use the characters " , then try this (enclose the whole command, including all arguments in quotes):

 eval "python ..." 

You can also try to "break the python node." Try to call crowbar.py without explicitly specifying the interpreter.

for this, the file must first add the executable bit:

 $ chmod +x crowbar.py 

and then in the bash script call it by name:

 ./crowbar.py ... 

The same call can be tried and “wrapped” in eval :

 eval "./crowbar.by ..." 
  • Unfortunately, nothing has changed - 3amunyk
  • Have you tried to enter exactly the same command in the bash script that you execute directly in the shell? without variables. - aleksandr barakin
  • Yes it works. Can the whole script lead? - 3amunyk
  • bash script? No, its contents do not matter. rather, crowbar.py content may play a role. Can you prepare a short, complete example ? - aleksandr barakin pm
  • Redid the question into a more detailed - 3amunyk