Problem wth spec chars in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem wth spec chars in script
# 1  
Old 08-20-2017
Problem wth spec chars in script

Hello

I would like to make a script which will get the line from file list (ex. passkey) and put it into further processing.
The main problem is that lines, in text file contains all specials characters, and whitespaces too, as these that was used as a extremmaly-safe passwords. I have written my passwords to .7z files on long list, but I can't find which one is propper for specific .7z file. So i am expecting "password" string and getting it line-by-line from passkey list and later each line into next 7z spawns.

Unfortunately bash stopping the run when first special character occurs on the list, and script trying to load it, going to problem


So I have created two scripts:
which I am calling ~/whiler /path/file.7z

1. 'whiler'
Code:
 1 while read line ; do
 2 echo "$line"
 3 time  expect ~/2.exp $1 "$line"
 4
 5 done<~/passkey.txt

2. and the expect cmdfile:
Code:
  1 #!/usr/bin/expect
 2 set filename [lindex $argv 1]; # Grab the first command line parameter
 3 set passkey [lindex $argv 2]; # Grab the 2nd command line parameter
 4 set timeout 1
 5 spawn 7z t $filename
 6 expect "password:"
 7 send "$klucz\r";
 8 interact

I also tried to make password list in doublequotes (") each line.

What can I do to use strings from file bypassing the injection bash ? Or maybe my scripts are bad?

Thanks for any help
# 2  
Old 08-20-2017
Is the ASCII 13 \r part of the password, or is this running on windows?

If it really is part of the actual password, you may get better results by using printf, maybe like this:
Code:
var=$(printf "%s%c" "\$klucz" 13)

Then pass "$var" to the second script as the third arg. Also assuming the leading $ is part of the password. Leading $ characters are a problem for shell.
# 3  
Old 08-21-2017
Thank you for your reply,

Quote:
Originally Posted by jim mcnamara
Is the ASCII 13 \r part of the password, or is this running on windows?
Hmmm, I have thinked that is to use as RETURN (ENTER) key. That is not a pasword - all password is in $klucz or $passkey variable and should came from shell script.

I am running that on ubuntu studio 16.04 where I have installed expect trough apt - version 1+

Quote:
If it really is part of the actual password, you may get better results by using printf, maybe like this:
Code:
var=$(printf "%s%c" "\$klucz" 13)

Then pass "$var" to the second script as the third arg. Also assuming the leading $ is part of the password. Leading $ characters are a problem for shell.
My main problem are marks like @, !, ;,\, and similar (really - i dont know which any others Smilie) - which used in bash console the have functions.
# 4  
Old 08-21-2017
Your answer is somewhat evasive.

Two ways:
1. use the printf method to embed punctuation and other odd characters. Unless you are using windows do not put \r in anything. expect gets a return from bash reading the script -- and it is a newline, \n

2. you can escape characters ( \ escape in front of each character, so \\ is read by the shell as a backslash, not escape). The shell takes them as literal characters, not some shell command -- example \*\# is an asterisk and an octothorpe (pound sign). Not a wild card and not a start of a comment.
# 5  
Old 10-30-2017
Quote:
Originally Posted by jim mcnamara
Your answer is somewhat evasive.

Two ways:
1. use the printf method to embed punctuation and other odd characters. Unless you are using windows do not put \r in anything. expect gets a return from bash reading the script -- and it is a newline, \n

2. you can escape characters ( \ escape in front of each character, so \\ is read by the shell as a backslash, not escape). The shell takes them as literal characters, not some shell command -- example \*\# is an asterisk and an octothorpe (pound sign). Not a wild card and not a start of a comment.
Thank You Jim for your help - and sorry for my late reply. The problem is still actual for me.

So, I suppose, that only proper way for me will be the 1st method. Due to diversity of the passkeys it would be easier than putting backslashes in 2000-marks passkey's for example. The lenght of the keys can differ, and the special chars qty is also random.

About the method you mentioned:

1. I would like to use only in linux, and on linux I also can prepare passlist (unix-type line endings and non viible characters on passlist).

2. If that method (printf) could help - maybe 'expect' will not be essential?

I have tried using expect due to problems with using 7z x -p$klucz (or $passkey) archive.7z
The $ mark is only for calling a variable. That is possible, that on the begginning will be Dollar sign - $ .

Maybe your solution would allow me to use passkeys without bash-processing it in native 7z commands? So, if I can use it as a full text in script - 7z x -p$passkeyfromprintf

Unfortunately - I am starting with bash programming - and I really do not have idea how to use your snippet. Would you like to show me any example how to start using this ?


So, if I would use it my simpler script: (could you please help me with that one?)
"7z t" - 7z TEST, which wll exit when the passkey is bad.

Code:
2var=$(printf "%s%c" "\$klucz" 13)
while read $klucz 
do  7z t -p$2var archive.7z
echo $2var
done<passkeylist.txt

Is that should work?
regards
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to split data with a delimiter having chars and special chars

Hi Team, I have a file a1.txt with data as follows. dfjakjf...asdfkasj</EnableQuotedIDs><SQL><SelectStatement modified='1' type='string'><! The delimiter string: <SelectStatement modified='1' type='string'><! dlm="<SelectStatement modified='1' type='string'><! The above command is... (7 Replies)
Discussion started by: kmanivan82
7 Replies

2. UNIX for Advanced & Expert Users

Script monitor website wth default tomcat script

Hi all, on our application server we have the following script that monitor the status of the website, my problem here is that i have edite the retries from 3 to 5, and the timewait to 120 second, so the script should check 5 times every 2 minutes, and if the fifth check fails it must restart... (0 Replies)
Discussion started by: charli1
0 Replies

3. UNIX for Dummies Questions & Answers

Problem with replacing chars in file

my file is : hello1 hello2 hello3_B,dummy,N Need to change to : hello1 hello2 hello3_B,dummy_01,N Can anyone help? Thank you. Please use code tags next time for your code and data. (6 Replies)
Discussion started by: Alyssa
6 Replies

4. Shell Programming and Scripting

Calling script from a RPM spec file

Hi, I want to execute a script "myscript.sh" in the %post part of a rpm spec file. Suppose the script is placed in /opt/path. Then simply calling like sh /opt/path/myscript.sh from %post part (of that spec file) will suffice? Or there is any other way? (0 Replies)
Discussion started by: saurabhkoar
0 Replies

5. Shell Programming and Scripting

Help wth Net::FTP in script sometimes fails but wsftp always works

Hi, I have a script that transfers files from a Solaris server to target unix servers. The script uses Net::FTP->put to write the files, which can be any number of files, not always the same. This script works flawlessly to many servers. For one particular instance of the script,... (3 Replies)
Discussion started by: csgonan
3 Replies

6. Shell Programming and Scripting

wth...can't read my post

something is wrong, I can read every post except mine. Very weird, and extremely anoying I can see replies to my post but can't view them, instead it keeps trying to save the page and open it from downloads... but the downloaded page can't be viewed. Don't suppose someone can copy/paste the thread... (0 Replies)
Discussion started by: gcampton
0 Replies

7. Shell Programming and Scripting

find 4 chars on 2nd line, 44 chars over

I know this should be simple, but I've been manning sed awk grep and find and am stupidly stumped :( I'm trying to use sed (or awk, find, etc) to find 4 characters on the second line of a file.txt 44-47 characters in. I can find lots of sed things for lines, but not characters. (4 Replies)
Discussion started by: unclecameron
4 Replies

8. UNIX for Advanced & Expert Users

Problem in FTP of file with chinese chars

Hi, I have a file in my PC with Chinese (PRC) characters. When I transfer that file into my AIX5.3 server through FTP, I get junk characters instead of Chinese chars. Last week I copied the content from my notepad and pasted in vi editor. The Chinese characters were correct, but when I try now,... (4 Replies)
Discussion started by: carthyc
4 Replies

9. Shell Programming and Scripting

How to convert C source from 8bit chars to 16bit chars?

I was using the following bash command inside the emacs compile command to search C++ source code: grep -inr --include='*.h' --include='*.cpp' '"' * | sed "/include/d" | sed "/_T/d" | sed '/^ *\/\//d' | sed '/extern/d' Emacs will then position me in the correct file and at the correct line... (0 Replies)
Discussion started by: siegfried
0 Replies
Login or Register to Ask a Question