Create assignment executable script - linux

Whats going on so for my unix/linux class the teacher wants us to create a create_assignment executable to use for all of our work or he takes off points. I have been trying for a week now and asked the teacher twice and it hasn't helped at all. so when I type ./create_assignment assignment3 it is suppose to make assignment 3 with a header I know I'm suppose to use chmod +x create_assignment to make it executable. I got it to make a create_assignment executable one time but it wouldnt do anything so I need to be shown how to make it executable and make it create the new assignment, I can post pictures if needed.

I am guessing you tried chmod u+x to make it executable?

Please share the code of your script. Have you checked file permissions? What user is running the job, and does that user own the destination folder/file?

Related

Run script from another home

I have a script in a user /home directory and I want to execute this script with an other user.
The script is in UserA home :
/home/UserA/command/command.sh
I want to execute this script with /home/UserB
What I did and wanted to know if there is an easier way to do it , is :
I gave the right to write and execute on this directory to other (chmod 703): /home/UserA/command
Is there a way to give the right only to UserB instead of other ?
In /home/UserB/.bash_profile , I added in the path /home/UserA/command
Another problem, I have, is that in the script command.sh, I use a variable $LISTPATH ($HOME/List) and this variable is defined in the UserA .bash_profile.
So when I start the script from /home/UserB, this variable is always empty.
Do I need to also add this variable in the .bash_profile of UserB:
$LISTPATH=/home/UserA/List
Thanks for your help
What a mess!
In my opinion:
You can create a group which UserB belongs to so you can assign this group to /home/userA/command and set right permission (such as chmod 730 /home/userA/command).
You better put the variable $LISTPATH on the top of your script.
Anyway, I think you better reorganize your project, you better put the script in /opt/< some subfolder>... instead of /home/userA/command.

Is there a way to default Go's os package calls to run under a specific user

Basically I cant use os.Mkdir or os.MkdirAll because it will create the directories as root. I know I can go the exec.Cmd route and set the syscall.Credential{}. But thats a bit cumbersome and I have to remove and replace a lot of code.
I was wondering if there was anything global I can set so calls to the os package will be ran as a specified user.
Thanks in advance.
In general, a process will make system calls as the user that ran the process. Maybe seteuid is what you're looking for?

touching a path name with varriable or other methode

I have a question about touching a path in a shell script. I'm making a script that clears some directories and add some files, now I'm trying to do this with touch /name/of/path instead of a find. I have some troubles with one of the paths this is becaus the last bit of the name changes in every file (the files are about working orders) now I tried some stuff like a variable or just the path with a * but it gives me an error
can anyone tell me if i need to change my variable for example.
the variable im currently using:
test='path/to/touch/annoy\ ing\ space*/'
and in my code I would like to execute this like
touch $test/test.txt
the error I get when running this is
touch: invalid option --'\'
I guess i get this option because there are \ in the varriabe but that is because there are spaces in the directory name I'm trying to enter.
I also tried something like this
touch path/to/touch/annoy\ ing\ space*/test.txt
but I also get an error when I try it like this, I read this is because I use a wildcard in touch and that isn't allowed. Can anyone confirm this?
If someone could give me an example or tip how to do this it would realy help me out. thanks in advance

Reversing/Debugging - Identifying symlinks in applications

I was wondering, is there any guidlines for identifying symlink related function in an application binary?
Let's take BusyBox for example, /bin/ping is a symlink to /bin/BusyBox.
How can I know identify the ping related functions within the BusyBox binary?
Thanks in advance :)
You can't generally do that.
In case of BusyBox, it checks upon startup which commandline was invoked to execute the binary (including the path to the binary itself). It then calls functions that provide the functionality that was selected based on the basename of the binary / symlink.
Again in case of BusyBox, most of the times the funktion names are closely related to the command name. But this is basically just coincidence: it could well be that someone created an exectable "A" that would call a function "X" when started via a symlink name "B" and function "Y" when called as "C".

hacking whoami to return a fake username

I've created a new whoami command which requires a fake username and have put it in the PATH by adding it to ~/.profile . It is created in a way that whoami is called before actual the actual whoami from Linux.
The main reason to do this is because I am remote accessing a Hadoop cluster and want the copied files to be under the fake username.
This works fine when I call whoami in the shell and even calling $PATH shows the path to my created whoami before everything else. But for some reason, when Hadoop is called, it doesn't pick the created `whoami'.
Can someone help me with how to fix this?
thanks
Most applications do not use whoami to determine a user's username or group. For instance, in bash you can use the command id to find more detailed information about yourself or id [username] (such as id root) to find out more detailed information about other users. Groups can be found with groups as well. Also, different programming languages, such as C, have their own methods of determining user identities such as the getuid() command.
If you really "need" to go as far as faking your user account, you'll need to go down to OS level and create hooks into the kernel/API that handles those methods.
Is it possible that you simply chown the files after they are copied instead?
UPDATE:
It appears that some releases of Hadoop do actually use whoami (my own implementation w/ clustering does not).
In this event, the best (a term loosely used) suggestion would be to move the legitimate whoami executable and create a whoami shell script that goes in it's place. The custom script should validate the current user and if it's "hadoop", return whatever faked username you want - otherwise return valid output. Igor's answer would work in this case.
I suppose that hadoop uses other PATH variable then you have in your shell.
You can tune its PATH and add the directory with fake whoami to its beginning.
When it is impossible,
you can write a small wrapper for whoami (I'm not sure that it is a good idea but you can do this if you want) that will run original whoami except when the script is executed by hadoop:
#!/bin/sh
WHOAMI=/bin/whoami.orig
if [ "$($WHOAMI)" = hadoop ]
then
echo fake
else
exec $WHOAMI "$#"
fi

Resources