473,379 Members | 1,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Automation of su password through shell script

i just want to do chmod on a file my_file but for that we must be su root. and finally that script will run through crontab
=========================
#!/bin/ksh
PASSWORD="pass123"
echo $PASSWORD>su root
chmod 777 my_file
=========================
I want to login as supervisor and then want to change the rights of the file before moving. but all has to be done through shell script which will be called through cron only


PLEASE HELP
Mar 17 '08 #1
7 70968
numberwhun
3,509 Expert Mod 2GB
i just want to do chmod on a file my_file but for that we must be su root. and finally that script will run through crontab
=========================
#!/bin/ksh
PASSWORD="pass123"
echo $PASSWORD>su root
chmod 777 my_file
=========================
I want to login as supervisor and then want to change the rights of the file before moving. but all has to be done through shell script which will be called through cron only


PLEASE HELP
You do understand how incredibly insecure this is, right? That said, you should not even attempt to do this, especially considering you are hard coding the root password in a script.

If I were your system administrator, I would sit down and have a chat with you about security and the root account, not leaving out why you should understand security before ever again giving you the root password.

Sorry for the rant, but that is the sys admin in me coming out. You really need to understand the severity of what you are trying to do and its consequences.

Regards,

Jeff
Mar 17 '08 #2
ashitpro
542 Expert 512MB
You can use 'expect' command for this purpose.
To start with the 'expect' follow the link.
http://www.unix.com/shell-programming-scripting/28194-using-expect-script-shell-script.html
Mar 18 '08 #3
micmast
144 100+
or use the sudo command

in the sudo file just add the aliases a user can execute without a problem, for example the chmod

then the user only need to do

sudo chmod ....

no password required
Mar 20 '08 #4
sicarie
4,677 Expert Mod 4TB
I want to login as supervisor and then want to change the rights of the file before moving. but all has to be done through shell script which will be called through cron only
I could be wrong, but I believe that if you set the cron as root, you will not need a password for this - it will be executed with root permissions.

(sudo crontab -e)

You could also have a look at another idea for creating secure scripts.
Mar 20 '08 #5
prn
254 Expert 100+
I have to go with sicarie's answer: if it needs root privs and it's going to be executed through cron, then put it root's crontab, not your own.

And please pay attention to Jeff's comment. Don't ever hard-code root's password in a plain-text script. That's just asking for trouble.

Besides, we kind of like Jeff around here. We don't want him to have a heart attack. :)

Paul
Mar 21 '08 #6
Unbelievable how you all have decided to answer a question by simply condoning the guy for asking the question. How do you know he isn't doing this on a home computer where your concerns don't apply? Please don't respond with "...it's always good protocol to be secure and not hard code passwords, blah blah blah..."

It would be great to come to a forum and actually read a response as opposed to a soapbox about possible irrelevant security concerns.

Jeff - perhaps the sysadmin in you could answer the question as opposed to addressing the topic of security?
Jan 30 '09 #7
Nepomuk
3,112 Expert 2GB
Dear err97002,
I understand that you may think this behaviour is not what it should be, but they are fully following both the posting guidelines ("Do not hesitate to point out better methods or technologies (if available) than the ones being used by the OP.") and common sense.

See, if someone asked you, how to use a hammer and the reason would be, because he was planning to kill someone with it, the problem would not really about using a hammer, would it? In this case, the solution the OP was planning to use bared risks, that he probably didn't fully understand. And even if it's a single user computer, there are certain risks with saving passwords in readable format.
@err97002
They may be irrelevant to you, but as a matter of fact, the answer will not only interest the OP but also other people who happen to find this thread and who may not be the only user on their computer.
@err97002
Well, although Jeff didn't answer the question, ashitpro, micmast and sicarie did. So, if you want to add something helpful, then please do. Otherwise, please accept that the direct route is not always the best route.

Greetings,
Nepomuk (Moderator)
Jan 30 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: news | last post by:
At the end of a PHP script, I'm sending a file via FTP to a server. I thought it'd be best to use a shell script in order to automate the FTP (logging in, changing to binary, putting the file,...
1
goldenjt
by: goldenjt | last post by:
We currently have an HP-UX 11.11 OS and Oracle 9.2 database. I am trying to automate a script in which it will stop the listener, for to complete a cold backup of the database. We have the listener...
7
by: rajataggarwal | last post by:
Hi, I am learning perl to do some test automation. In my perl scripts I need to source shell script. Can someone tell me whats wrong with the code below. #!/usr/bin/perl system "source...
9
by: niteck07 | last post by:
I am using following shell script to ftp files to another server but this is failing as the shell script changes the user name for the ftp login the correct user name is 'ag\invprint' which the...
3
by: telduivel | last post by:
Can someone please help me with this: I have a python script, that at some point calls a linux bash script (.sh). Starting the shell script is the last thing my python script needs to do, so I...
2
by: jallam | last post by:
Hi, I have a Python script to upload the Invoice data which is in .csv file to OTM (GLOG) system. I'm running this script using the command(given below) using a shell script and capturing the...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
1
by: rasmidas | last post by:
Hi, I have written a shell script, in which I am connecting to the oracle database and doing some manipulation. while I am running the script, its showing me the messages I am displaying in the...
8
by: xtremebass | last post by:
Hi Bytes.. i have need to assign Mysql Database DataField value to shell script variable . is it possible ? i have tried like this .. got error.. #!bin/sh password=xxx mysql -u root...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.