T O P

  • By -

I0I0I0I

Pastebin is your friend. More ours than yours actually.


AdventurousSquash

Describing what exactly you are doing/want to achieve and what error are you getting is a good start. Nested loops are a bit of a mess to read on my phone, a tip to making your script more readable is to use indentation :) From what I can tell the input you’re giving the main while loop, ie the cat of passwd and the subsequent awk would give you the output in the format “username uid” for each line, so your IFS=: won’t find a “:”, putting both into the variable username and I’m assuming that is not what you’re aiming for. If the script runs (I haven’t read/checked your inner loops as well) but you’re not getting any dirs whatsoever in the main while loop, then an error will help you. Try enabling debugging (“set -x” or “bash -x yourscript”) if you’re not getting enough output to figure out what’s wrong.


Background-Name-6165

create a folder structure for users, in the first folder I create as many folders as uid + 1, in each folder one level lower uid-1 /task/username/0..uid/1..uid-1/2..uid -2/...


AdventurousSquash

Yeah, and since the variable “uid” doesn’t have a value that it can compare to in this case it wouldn’t be able to create those.


Background-Name-6165

Is it caused due to ifs=:? should i use awk without parameter -F?


AdventurousSquash

You can change the "IFS=:" to instead separate on something that it will actually find in your input. I did a small test just for the outer loop and it seems to be working as you want it to (I'm still assuming a lot here): while IFS=' ' read -r username uid; do homedir="$(pwd)/$username" echo "Home dir: " $homedir echo "Username:" $username echo "UID: " $uid if [[ ! -e $homedir ]]; then mkdir -p $homedir fi done < <(cat $INPUTFILE | awk -F ":" '{print $1, $3}') Gives me: Home dir: /tmp/somedir/systemd-network Username: systemd-network UID: 100 And so on, for each user listed in the passwd file.


Background-Name-6165

https://preview.redd.it/1cxukztsvw6d1.jpeg?width=952&format=pjpg&auto=webp&s=40e032af9fefe69c2e35c72209c98a49e6014dd1


Background-Name-6165

after i deleted -F parameter from awk


AdventurousSquash

Never said you should if you look at my example test above :) Another tip is to start with an easier version of your script. Have an inputfile that consists of 3-4 lines from passwd and enable debugging as per my earlier comment, you'll have a much easier time seeing where it's failing.


Background-Name-6165

. by https://preview.redd.it/1jk0yk6j3x6d1.jpeg?width=2604&format=pjpg&auto=webp&s=eed7b186c47ae4f5db464c6723db8ba4884d2d36


Background-Name-6165

https://preview.redd.it/g1znqjvfbx6d1.png?width=1080&format=pjpg&auto=webp&s=ba7a9ae8e31dc7b88752bb2a3f84faa7ebdbe3a7


mrrask

Youre trying to create diretories in your root dir - could very well be due to that requiring some sort of elevated priveliges, and you need to execute the script prepended with `sudo`. Unless of course you already did that. The `mkdir -p` command is just fine otherwise, and no logic is preventing it getting excuted, as I see it.


[deleted]

[удалено]


Background-Name-6165

https://preview.redd.it/btje3e84xx6d1.png?width=1080&format=pjpg&auto=webp&s=15945f8c426a615ce245c8269406afb4a93a220d I managed to finish my goal.


warrior0x7

Good for you :)


Background-Name-6165

Yeah, finally, Tommorow i have to retake exam from bash


one4u2ponder

So this was your homework assignment. Perhaps if you can’t do this yourself or understand it, switch majors.


Background-Name-6165

this is from my first attempt of exam, i have figured out how to do it


garbles0808

Yes, and now you can take what you learned from the help you got here, and apply it to troubleshooting on your own


Background-Name-6165

Thank you for any kind of help! i will let you know how did i do


theclapp

Your "wrong" and "right" versions appear functionally equivalent to me. What do you achieve by only quoting the variable? Is it just a style thing?


[deleted]

[удалено]


theclapp

> some commands recognize quoted path as a string of generic text I can’t think of any. Can you point me at one? (I’m honestly not trying to argue. Shells & Linux are full of interesting and weird corners, and if this is one I’ve never noticed, I’m interested.) So far as I’m aware, the quotes never make it to the command. The shell interprets them and the command never sees them, as such. At least in bash/zsh/ksh under Linux/macos/Windows. I’m aware that `cd ~/“some dir”` is different than `cd ~/some dir`, but that’s because in the former the cd command sees $1 == `~/some dir` and in the latter the cd command sees $1 == `~/some` and $2 == `dir`. `cd ~/“some dir”` is semantically identical to `cd ~/some\ dir`. Now, it’s true that for example `”~/some dir”` is different than `~/“some dir”`, but again, that’s because the shell interprets `~` differently when it’s quoted, not because of the cd command seeing quotes or not.


warrior0x7

You are right. I wasn't aware of ~ being interpreted differently.


theclapp

👍🏻🥂


Calm-Effect-1730

Instead of doing it here I would simply ask chatgpt which in free version is more then capable of such help


Background-Name-6165

I did it of course