LDAP Script Help - Put ldapserach command results in single quotes - bash

The following script works, but I need help with one change. Right now using lday serach, and a little utility called GETPASS, this script will pull a listy users, from a specified context out of an LDAP directory, compare their LDAP password, to an unused attribute, If different, add it to the unused attribute called carLicense, and then send it in SHA 1 format, up our google APPS domain, with Google Apps directory sync. The one problem, is that it when it returns the ldapsearch, it works fine with a user in this format:
cn=joebloe,ou=googletest,o=someorg
However, if the usename has a space in it like this:
cn=joe bloe,ou=googletest,o=someorg
the script will fail as it does not know how to deal with that space. In this situations, a single quote, around the DN will solve the issue IE:
'cn=joe blow,ou=googletest,o=someorg'
However, I have tried to alter the script to address this need of mine, and I am failing miserably, please see a copy of the script in Pasetebin below. Any help with be deeply and GREATLY appreciated, as this is currently my only stumbling block to success.
http://pastebin.com/htWxsNXj

Replace the first line of generating result file (in your pasting is line 66) with:
echo "dn: '$RESULT'" >> $SCRIPTPATH/gadspwsync.ldif
If it won't help, don't remove the file in line 75. Check the content, show us the first line, then show the expected content.

Related

Is there a way CMD can open a folder with an emoji in its name by using os.execute in Lua 5.2?

As soon as I try to access a folder/file containing an emoji in its name from my Lua 5.2 script, for example like this:
os.execute('start "" "' .. path .. "\\scripts\\menu\\📄 My Scripts" .. '"')
The Windows' Command Prompt simply refuses to open it with the following error message:
I'm aware Windows' Command Prompt doesn't support emojis and therefore is not possible to make it work just like that, but my doubt is if won't exist some workaround or whatever I can do to ensure any Windows/Unix user is going to able to get the folder open by my Lua script without any problem.
I have tried i.e. things like use the codes instead (1246 and U+1F4F0 in this page facing up case) without success. Couldn't I for example simply use some kind of "wildcard" instead? I mean, knowing it's always going to be the very first character in the name. Or, well, any other ideas will be welcomed, cause nothing I'm trying really seems to work...
Of course if it's going to represent any problem I'll simply refuse to use them, but it came in handy for some "first sight" folder distinction and, if possible, I'd like to can count this little visual resource 🙄
This is a Problem about how the string is constructed.
I found only one solution with [[command "path"]] (on Windows 11 and Lua 5.3)...
os.execute([[start ]] .. path .. [["\scripts\menu\📄 My Scripts"]])
-- My Testpath is/was: os.execute([[dir "%localappdata%\nvim\📄 Lua"]])
...the long string ([[]]) will not be interpreted (coercionated) by Lua.
That also have the side effect that you can use single backslashs with that kind of string.
Environment variable expansion (e.g. Windows: %localappdata%) only works inside doublequotes.
Single quotes instead ([[command '%localappdate%\path\']]) will not work (expanded).
os.execute accepts only ANSI-encoded strings (win-1252 in European Windows), but it is unable to encode an emoji.
Hint: you can create .bat-file to do the task for you and invoke it from Lua with os.execute.

Adding multiple files with one command

I tried to give a sample of a list of my titles. Here it is:
'197. Module Introduction.txt' '198. Our Starting Setup.txt' "199. What's So Complex About Forms.txt" '200. Dealing With Form Submission & Getting User Input Values.txt' '201. Adding Basic Validation.txt' '202. Providing Validation Feedback.txt' '203. Handling the "was touched" State.txt' '204. React To Lost Focus.txt' '205. Refactoring & Deriving States.txt' '206. Managing The Overall Form Validity.txt' 'Assignment 5: Time to Practice: Forms.txt' '207. Adding A Custom Input Hook.txt' '208. Re-Using The Custom Hook.txt' '209. A Challenge For You.txt' '210. Applying Our Hook & Knowledge To A New Form.txt' '211. Summary.txt' '212. Bonus: Using useReducer.txt' '213. Module Resources'.txt
All those titles were in a text file named lectures.txt.
I wanted to create a series of titled blank text files in a folder I had already created to receive them. Each text file should have the specific titles as in that example list. Ultimately I would be creating nearly 500 files, but all of them would have very specific meaningful titles.
I tried to follow all the instructions I found on this forum and elsewhere, on a very long search for help. None of them directly addressed my problem.
They all gave answers for creating multiple files with meaningless names. I don't see the utility in creating a bunch of files named 1.txt, etc, or a.txt, or some combination with a leading standard meaningless lead like filename, or sample...
I may be wrong about that lack of usefulness, but at the very least, it's not what I tried to ask and get an answer for.
I already have the meaningful filenames I want, a lot of them. I want to create many empty text files with names that I already have.
The only remotely useful suggestion (for me) that I got was using touch from a linux or bash prompt.
I found that if I wrapped my titles in quotations and separated the titles by a single space I could get the touch command to kind of work. I also discovered that my file titles could not contain any forward slashes ("/"). Nobody explained to me that the titles had to be wrapped in quotes. I figured that out quickly. Nobody told me how to separate the filenames. I experimented until I found a separation that worked.
I tried some experimenting with the {} bracing and the touch command but wound up not being able to figure out how that could help me in my particular case.
Also, I don't know if it has to do with a buffer on the bash or in PowerShell (I tried using both the Git installation in Windows 10 and bash from PowerShell 7.2.1, but I found that only about seven titles in the list would be touched. The rest resulted in a command not found error.
I broke up the list into about seven titles each and ran touch on each of those filenames (my titles) list segments. That way, on that very list sample I display above from my lectures.txt file, I got my empty text files created successfully, even though I had to do it in three touch commands.
I may have confused some of the people who tried to help me by putting all the titles in a text file that I named lectures.txt.
The contents of that file were the titles I wanted for my text files. Thank you so much those who did reach out to me.
I had already found something that might work in bash but I couldn't get it to work. It was roughly on the line of
`touch prefix{1..3}.txt`
This had the same problem that all the other command suggestions I found had as well, like
echo > filename.extension
The same for the apparently most popular
for /l %a in (1 1 10) do type nul > "%a.txt"
which created ten files named 1.txt through 10.txt. That was not the least bit useful to me.
I know my question got voted down as being exceptionally bad, but I'm editing and adding what I found out, so maybe sort of answering my own question.
If you are looking to do what I'm trying to do, and not just create meaningless filenames, I hope you will find some of what I did helpful. Here's a list of suggested solutions of which NONE did I find useful.
https://techpp.com/2021/08/22/create-file-using...
https://www.quora.com/Can-you-create-multiple-f...
https://www.howtogeek.com/725207/how-to-create-...
How to create multiple empty files on cmd(Windows).
Create multiple files with Powershell?.
https://www.laptopmag.com/how-to/create-multipl...
Remember that using space in bash is not recommended, but if you need to...
You can try something like that:
counter=1
for title in $(cat lectures.txt)
do
touch "$counter - $title.txt"
counter=$((counter+1))
done
EDIT
I only added the title on lectures.txt
NEW EDIT
If lectures.txt has 1 title per line you can do this:
while IFS= read -r line || [ -n "$line" ]
do
touch "$line"
done < lectures.txt
Get-Content -Path '.\lectures.txt' | ForEach-Object { New-Item -Path ".\$($_)" }
or using aliases it's: gc '.\titles.txt' | % { ni ".\$($_)" }
from a powershell console at the required folder and enter the command.

S3 delete file programmatically which ends in line feed (%0A)?

I have a bunch of files in s3 that show in the console as ending in "%0A". I'd like to programmatically delete these files.
When I use this method and set the key with suffix "%0A", I get no error but the file is not deleted.
I don't know how it looked when the file was initially written.
S3 Console should be able to delete it no matter what characters it contains or how broken it is (if we're talking about same thing). Do you have enough permissions?
When doing it other ways, first you need to figure out if "%0A" is actually part of the name or is a url encoded LF character ("\n"). Keep in mind that you might not see other non-printable characters as well. The best way to determine this will be to open it in Amazon Console, choose S3 in Service menu, find your Bucket and click on your file, note the object's Link.
If "%0A" is part of the name, you will see object name as "foo%0A", but in the link it will look like "foo%250A". In this case, s3 rm s3://BUCKET/foo%0A should do the trick.
If "%0A" denotes a url encoded "\n" character, then you should see object name (just above tabs) as just "foo", but will see "foo%0A" as object name in the url. In ths case you need to embed new line into the key when issuing s3 rm command. This depends on you operating system. E.g. on linux/unix you will enter it like this:
aws-cli s3 rm 's3://BUCKET/foo
'
Note the quotes and that the closing quote is at the begining of a new line. This will make new line part of the value passed as the command line parameter.
Also note that aws-cli might be called just aws on some system, but given you provided s3 rm command as an example I assume you already know what it is on your system. And if using PowerShell on Windows, use backtick in place of quotes.
Now, check the object's Link and see what other characters are there. Looking at your examples and issues you report, I suspect there is more then one in your file names. Important point here is that your object name might include more non-printable characters and you won't see then in S3 console, but Link will include them all in URL encoded form. So, you can extract actual exact name from the link. Note that both aws-cli and programmatic interface you linked take actual name, not url encoded one. So, if you use aws-cli, you will need to embed all non-printable characters into command line parameter. And if you're using programmatic interface you'll need to embed them in the key string you supply to the call (e.g. putting "\n" instead of new line). Though I consider this part pretty obvious. And believe you'll know what to do once you see your actual file name with all the non-printables in it.
Try this
aws s3 rm "bucket_name"$'\r' --recursive
Worked for me.

WebSphere: Unable to change both stderrfilname and stdoutfilename at same time

In WebSphere Application Server 8.5.5 I'm having problems setting the native_stdout and native_stderr log paths from wsadmin jython script.
Everytime I set one path, the other is blanked out. i.e. set to null.
I presume I need to form a line of code that sets both paths simultaneously but have been unable to create the correct syntax, if this is at all possible.
The code to produce one path change looks like:
srv = AdminConfig.getid('/Cell:mycell/Node:mynode/Server:server1/')
processDef = AdminConfig.list('JavaProcessDef', srv)
AdminConfig.modify(processDef, [['ioRedirect', [['stderrFilename', '${LOG_ROOT}/server1/new_stderr.log']]]])
AdminConfig.save()
This works fine but when I then use the same script to set the stdoutFilename, it blanks the stderrFilename previously set.
It seems to make no difference at which point I commit the changes using save.
Any help with this issue would be greatly received!
You're right, even though the manual elsewhere warns that AdminConfig.modify() might append to lists when you don't expect it to. I observed the same thing.
Here's the pattern you want to be safe, clear it out and set both properties at the same time:
AdminConfig.modify(processDef, [['ioRedirect', []]])
AdminConfig.modify(processDef, [['ioRedirect', [['stderrFilename', '${SERVER_LOG_ROOT}/my_stderr.log'], ['stdoutFilename', '${SERVER_LOG_ROOT}/my_stdout.log']]]])
After this, you can do this for a simple verification:
print AdminConfig.showall(processDef)
But watch the output closely as it is not pretty-printed

modifying the bash prompt on mac

On my bash prompt, I would like to see just the name of the current directory followed by "$" in different colours.
So I used this code but when I have a long typed command, I see the cursor in different place than where the typing is taking place. How can this "hard to describe" problem be fixed? Thanks
PS1='\[\e[0;36m\]\W\[\e[m\]\[\e[1;31m\]\$\[\e[m\]'
Use a carriage-return after outputting the current directory, I've done this for years and it works a treat, something like:
if [ "$PS1" ]; then
PS1="\[\e[0;36m\]\W\n\[\e[m\]\[\e[1;31m\]\$\[\e[m\]"
fi
You always have your current directory (no matter how long) on top of your $ prompt.
I put other info up there as well like username, machine name and exact time and date. I colour them differently so they really stand out. Helps if you have multiple sessions going on, on different machines with or without root(!) privileges (have to be root when deploying a complete rebuild). And has saved the day many times when I need to know when I did something or other (ok, it's when that task ended - but still helps).
But most of all, it's great to know your current directory by simply looking at your command line prompt :) )
Don't know how other people work efficiently without it!

Resources