Trying to create a script to run as root, permission denied


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to create a script to run as root, permission denied
# 8  
Old 04-11-2013
no, you are right...I am a total newbie to UNIX, so I didn't know.

How would I write this script to tell the script to run the second script which is located in the same directory as the first? (sorry if confusing)

Ex. If I put both of these files on a USB stick and plugged it into a Mac and ran this script. Where does Mac mount the USB at by default? /dev/???

---------- Post updated at 03:11 PM ---------- Previous update was at 03:07 PM ----------

Quote:
Originally Posted by DGPickett
Did the script stuff run from your shell prompt, interactively? Who or what calls the script (and has to provide environment): cron, ssh, webserver, ???
Not quite sure what you mean by this...sorry.
I would just put these files on a USB, then double click on the first script, which would authenticate as root and then call the second script. Is that what you are talking about?
# 9  
Old 04-11-2013
Don't get too hackeresque, we seen that movie. When you plug a usb drive into a system, it can be automounted and some systems like windows can autorun things on it. Not being a mac hacker, I am not sure how to set up either.

Once it is mounted, for any script run, its location will discernable from $0 and $PWD, and possibly $PATH, as the only way to run it is with an absolute path, a relative path or a $PATH dir entry. The apparent script location may not be a real path, if it was run through a symbolic link, but you can run realpath to find out or chain up .. until root (inode .. = inode . )

In a unix file system:
  1. there are many types of inode: directory, flat file, symbolic link, named pipe, raw device, cooked device and maybe a few I forget. Read the source, Luke, and man pages, too.
  2. A directory is essentially a list of entry names and their inode numbers -- nothing else!
  3. The inode numbers are relative to the device.
  4. The root tree starts on the root device, but you can mount file systems over directories, hiding those directories and all that might be in them on the parent device, and establishing another device for that sub-tree. You can see some oddities in such a neighborhood in the ., .., directory's entry name inode numbers, as I recall. df and mount show you all the mount points including root, read off root!
  5. One device can be mounted upon another.
  6. Some variations of ls and find show inode numbers and device numbers.
  7. A symbolic or soft link contains a path, relative or absolute, to a replacement entry. The ln command creates both
  8. hard links (two directory entries with the same inode #, like /. and /..) and symbolic or soft links or sym-links (-s), rather like windows shortcut file *.lnk.
  9. The rm command is a wrapper for unlink(), as a file is not really removed until all links, directory entries to the inode, are destroyed (the inode has a count, which you see on ls -l), and even then the inode is parked somewhere like lost and found if it is still open at remove time. SOme tolls remove temp files after openeing them, so there is never any collision of names, cleanup, prying or interference.
  10. Only the system can hard link directories (every child directory's .. is another link on the parent directory inode, plus . and its entry in the grandparent), so symbolic links on directories are very popular. Not sure offhand about hard links on other inodes! Windows NTFS allows hard links, too, which I noticed under CygWin just recently! I am not sure if Mozy double-charges me to back them up! Smilie
  11. If I use a symbolic link, find -type f ill miss it unless I say -follow. The ls option L makes it punch through sym-links. Using a trailing / or /. forces a trip through to the real inode, too.
  12. NFS and its buddies can mount remote files in the local tree. All calls just wander over to the real system on the net.
  13. Traditional simple file systems are initially configured with just so many inodes on the device, and you can run out.
  14. Complex file systems can be runing interference behind the facade to make many devices into one, slide space from one place to another, add ACLs for extended permissioning, mirror, RAID, quota, .... They can manufacture inodes on demand. They can make for a slow reboot from any ungraceful shutdown, too. SAN systems may use NFS or have proprietary connection hardware and protocols. Solaris Client file systems can use local disk space as a persistent cache for NFS mounts. And so the head starts spinning.
  15. Welcome to UNIX file land.
This User Gave Thanks to DGPickett For This Post:
# 10  
Old 04-12-2013
Haha, sorry I am not trying to be a hacker.
I ended up finding out what I need to make this work. It's not perfect by any means, but it gets the job done for what I am looking for. If anyone knows how to put these two scripts into one, that I could just double click on when I copy it to the desktop of any computer, that would be awesome, otherwise I think I am good to go.

First script logs me in as root, and then calls the second script to run.

ClickMe.command
Code:
#!/bin/bash
clear;
sudo Desktop/ifs/IFS_Perm.command

IFS_Perm.command
Code:
#!/bin/bash

clear ; echo This script will put a system configuration file into your Mac OSX that will assist with UNIX permissions on the IFS
sleep 2
clear ; 
echo Moving Working Directory to the System Directory
cd /etc/
sleep 2
echo Creating a new file with correct permissions, please have system root password ready...
sleep 3
sudo cat <<EOF >> launchd.conf
umask 000
EOF
echo Process has completed, thank you. 
sleep 3
killall Terminal

exit 0

Thanks all for your help, and thank you DGPickett for your lenghty, informative information!
# 11  
Old 04-12-2013
Typically, I just press the command+u key combination, launch the terminal, type sudo followed by a space, then drag the desired script to the terminal window.

For double click simplicity, I will usually create a "payload free" package that runs the script as a preinstall script. This also has the advantage of being deployable through a wide variety of remote management products. You don't have to train field techs how to use the terminal either. Smilie
# 12  
Old 04-26-2013
It all makes more sense if you know a little about what is underneath. It is pretty simple, really, but as Einstein said, 'not too simple', in this case, to be useful and versatile. It's like remembering that all the nice stuff on your screen is one pixel deep (unless you have an old ti pc) and represents the last repaint.
# 13  
Old 04-26-2013
This command does not do what you think it does:

Code:
sudo cat <<EOF >> launchd.conf
umask 000
EOF

Let me explain in detail the order which it does these things.
  • Redirects 'umask 000' into stdin
  • Redirects stdout into launchd.conf
  • Forks and executes 'sudo cat', letting it inherit these I/O redirections

You see the problem? It opens the files before it runs sudo. It has to -- you can't alter stdin and stdout for a program that's already running, you have to set them up first. By the time you call sudo, your shell has already tried and failed to open the file.

You have to run all that code inside sudo, since sudo is the thing with elevated permissions.

Code:
sudo bash <<EOF
        echo "umask 000" >> launchd.conf
EOF

# 14  
Old 05-01-2013
I'd think you'd need:
Code:
sudo bash -c '
cat <<EOF >> launchd.conf
umask 000
EOF
'

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

Mkdir: cannot create directory `/home/phpmy/html': Permission denied centos

for incompatibility installation problems, I've decided to reinstall Centos 6.3 as can be seem from the df output, I've partitioned both / and and /home directories $ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda8 12G 5.3G 6.5G 45% / tmpfs ... (2 Replies)
Discussion started by: jediwannabe
2 Replies

2. Linux

/var/lock/subsys permission denied for root

Hello I have simple line of code here: FILE *lockfp = fopen("/var/lock/subsys/processName", "w"); which is denied even running as root. The result is locking failed for the following reason: Permission denied How is this possible? Why is this happening? Thanks for your... (4 Replies)
Discussion started by: flagman5
4 Replies

3. Shell Programming and Scripting

Help with Permission Denied on script with sed

I am trying to develop a script to replace a lowercase URLs with an upper case URLs in HTM files. Basically.. replace href="somelowercaseurl" with href="SOMEUPPERCASEURL". In place. the href's are not located in any specific position in the file. Here is my shell script : export... (5 Replies)
Discussion started by: smarty
5 Replies

4. AIX

Permission Denied issue on AIX 6.1 using Root

I have the following problem on my AIX 6.1 server. I logged in with Root ID to this folder etc/opt/symantec/scspagent/lib/instfunlib I try changing the folder permission but I keep getting this output : chmod: /opt/symantec/scspagent/lib/instfunlib: Permission Denied I did a listing on it... (3 Replies)
Discussion started by: mcdsweet98
3 Replies

5. UNIX for Dummies Questions & Answers

mkdir: cannot create directory `/builds/somedir/': Permission denied

Hi, I am trying to run a shell script which contains an mkdir command as part of the execution. The script fails with the following error: mkdir: cannot create directory `/builds/somedir/': Permission denied The user running the script is 'harry' and belongs to group 'school'.... (5 Replies)
Discussion started by: Technext
5 Replies

6. Shell Programming and Scripting

Can root user run chmod 000 permission shell script?

Hi, I have a shell script file which is set to access permission 000. When I login as root (sudo su) and try to run this script, I am getting the Permission denied error. I have read somewhere that root admin user can execute any kind of permission script. Then why this behavior? However, I can... (1 Reply)
Discussion started by: royalibrahim
1 Replies

7. Shell Programming and Scripting

shell script and Permission denied

Have the following in a .sh file. printf "Installing ... \ r" cd $ ORG_DIR / a_a . / configure> error.log Make 1> error.log 2> error.log make install> error.log But when I run I get the following. install.sh: line 270:. / configure: Permission denied make: *** No rule two make target... (3 Replies)
Discussion started by: Mumie
3 Replies

8. UNIX for Dummies Questions & Answers

Permission denied when changing root password after reset

I have a Solaris 10 machine that I didn't know the root password to so I went into single user mode and removed the password from the shadow file and rebooted and I am able to login with no password now. But my problem is that when I try to change the root password from no password to something... (0 Replies)
Discussion started by: darkone_d1_2000
0 Replies

9. UNIX for Dummies Questions & Answers

Unable to run program, Permission denied

Hi All, I am working on Solaris Sparc 9 and I developed application and in that I want to open any file when any action is happened but when I am trying to do the same.I am getting the error -- "Error launching /test.txt", "", "Process.execAndWait", "java.io.IOException: Cannot run... (0 Replies)
Discussion started by: smartgupta
0 Replies
Login or Register to Ask a Question