LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-05-2014, 12:32 PM   #1
rjnlinux
Member
 
Registered: Sep 2009
Posts: 41

Rep: Reputation: 0
help with script


#!/bin/ksh

user1=`who am i|awk '{ print $1 }'`
echo $user1

==================
above is my script
This works from prompt
however it does not work from cron

please help
 
Old 06-05-2014, 12:48 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,716
Blog Entries: 14

Rep: Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039
The environment one gets when logged in to a shell session is not the same as the minimal environment cron or other background tools such as init scripts have.

Typically you have to include in such scripts the environment you want.

Your script is using the commands "who" and "awk" but is not specifying where they are.

Type "which who" and "which awk" from command line and you'll see full path to the commands. Use those full paths in your script.
 
1 members found this post helpful.
Old 06-05-2014, 02:09 PM   #3
rjnlinux
Member
 
Registered: Sep 2009
Posts: 41

Original Poster
Rep: Reputation: 0
i tried the following

#!/bin/ksh
set -x
user1=`/usr/bin/who am i|/bin/awk '{ print $1 }'`
echo $user1 >/home/oraerp/scripts/out.log


No...this does not work from cron
 
Old 06-05-2014, 02:51 PM   #4
rjnlinux
Member
 
Registered: Sep 2009
Posts: 41

Original Poster
Rep: Reputation: 0
the solution is as follows

create a file which has variables I require
source this file in the script

Now the script works from cron as required
Enjoy !!
 
Old 06-06-2014, 09:56 AM   #5
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,716
Blog Entries: 14

Rep: Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039
You really don't have to create a separate file and source it. Variables within your main script are the same as variables sourced from another file.

I suspect you had a lot more going on in the script than you shared.
 
Old 06-07-2014, 12:18 AM   #6
shameer
LQ Newbie
 
Registered: Jun 2014
Posts: 1

Rep: Reputation: Disabled
Unhappy add multiple users script

hi friends
iam new to linux os,iam working as a administrator in engineering colg.i have to add 60 users(userid:rollno1,rollno2,...rollno60)can any one help me how to create multiple users using scripting
 
Old 06-09-2014, 07:40 AM   #7
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,716
Blog Entries: 14

Rep: Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039
Quote:
Originally Posted by shameer View Post
hi friends
iam new to linux os,iam working as a administrator in engineering colg.i have to add 60 users(userid:rollno1,rollno2,...rollno60)can any one help me how to create multiple users using scripting
Please do not piggyback your new question on an existing thread. Only people that subscribed to the original thread would see your new question. Instead please start a new thread which will likely be seen by more people until it has replies.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 1 07-13-2012 01:03 AM
Shell script, Perl script, command or utility to convert Binary to text Perseus Programming 26 07-12-2012 06:00 AM
[SOLVED] bash and xterm: how make apps started by and for a script persist when script terminates porphyry5 Linux - General 4 06-15-2011 01:27 PM
[SOLVED] Script question: create a shell script in kde to log in on a server with ssh c4719929 Linux - Newbie 1 01-31-2011 03:05 AM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 08:40 AM


All times are GMT -5. The time now is 12:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration