Sponsored Content
Top Forums UNIX for Advanced & Expert Users Syntax when using the 'exec' command Post 302985381 by Corona688 on Tuesday 8th of November 2016 05:28:28 PM
Old 11-08-2016
Quote:
how can i automate -- inside of the script -- for stdout and stderr to be re-directed to the same file, something that usually requires entering an admin password.
That is easy.

Code:
exec 1>filename
exec 2>&1

echo "from stderr" >&2
echo "from stdout"

None of the above requires root... I think you will discover that the problem is not exec -- the problem is the file itself. Perhaps the file is owned by root, preventing you from writing to it? Show ls -l filename please.

If your script runs with insufficient permissions, it cannot get more. Period. Full stop.

Either run it with sufficient permissions or fix the file so it doesn't need extra permissions.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

using the -exec command

linux redhat 8.0 I am getting accustomed to using the -exec command to get around my databse.. and use it to edit and update files..! is this more apllicable than jumping from one directory to the other.. I have set up the databse so that the inode #'s are accessable and can get me from one... (0 Replies)
Discussion started by: moxxx68
0 Replies

2. Shell Programming and Scripting

exec command

hai i want know the difference between two shell scripts those are 1) a=2004 echo $a #output------2004 exec < inputfile while read line do echo $a #output-------2004 a=2005 echo $line echo $a ... (1 Reply)
Discussion started by: g_s_r_c
1 Replies

3. UNIX for Dummies Questions & Answers

Need help with -exec cp command.

I have a ksh script that contains the following: find /dir1/dir2 -type f -name "FILE.*" -newer /dir1/dir2/afterme.txt -exec cp /dir1/dir2/dir3 {} \; When I run it from the cli, it runs fine. When I run it from the ksh script I get find: missing argument to `-exec' I also tried -exec cp... (40 Replies)
Discussion started by: bbbngowc
40 Replies

4. Shell Programming and Scripting

exec command

can any one pls explain the meaning of exec 1<&5 ?? its urgent (2 Replies)
Discussion started by: santosh1234
2 Replies

5. Shell Programming and Scripting

exec command help

All, I am using below shell script to output the content to outputfile.txt. What I am looking for is in addition to outputfile.txt, I want the output to be on standard output too. exec > outputfile.txt echo "Starting " echo "ending" (5 Replies)
Discussion started by: basic_shell
5 Replies

6. Shell Programming and Scripting

exec command

How can I use the exec command to log my korn shell session to the screen and the log file? Currently I have this command: $exec 1> ${LOG} 2>&1 This logs the output to the log file only. I want it to go to the screen also. Is this possible with this command? thanks. (10 Replies)
Discussion started by: djehresmann
10 Replies

7. UNIX for Dummies Questions & Answers

Exec command

Hi can some one explain the following command , It would really help if some can really elloborate on what is happening out here export PATH | exec /bin/sh ./auto_approve :q P.S: This is the first time i am using exec ,so an elloboration what does it do and what is the use of the :q will be... (1 Reply)
Discussion started by: Sri3001
1 Replies

8. Shell Programming and Scripting

exec command help

Hi, I have the following lines in a script : . . exec < some_file . . . I have very little idea about exec command. I would like to know what this does and what will happen if the file some_file does not exist. Specifically, I would like to know whether the lines following this... (5 Replies)
Discussion started by: elixir_sinari
5 Replies

9. Shell Programming and Scripting

Exec command - what is it doing here?

Hi all, Forgive me for asking for help with my first post, but I am struggling here. I've been asked to translate a bash script into a Windows script (probably batch or powershell, not sure yet), so the first step is obviously understand what the bash script is doing. But I have no experience in... (5 Replies)
Discussion started by: el_foz
5 Replies

10. Shell Programming and Scripting

Linux find command seems to not transmit all the result to the '-exec command'

Hello. From a script, a command for a test is use : find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb ! -newer /tmp/000_skel_file_end -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' Tha command... (3 Replies)
Discussion started by: jcdole
3 Replies
PPPCTL(8)						    BSD System Manager's Manual 						 PPPCTL(8)

NAME
pppctl -- PPP control program SYNOPSIS
pppctl [-v] [-t n] [-p passwd] [host:]Port | LocalSocket [command[;command]...] DESCRIPTION
This utility provides command line control of the ppp(8) daemon. Its primary use is to facilitate simple scripts that control a running dae- mon. The pppctl utility is passed at least one argument, specifying the socket on which ppp is listening. Refer to the 'set server' command of ppp for details. If the socket contains a leading '/', it is taken as an AF_LOCAL socket. If it contains a colon, it is treated as a host:port pair, otherwise it is treated as a TCP port specification on the local machine (127.0.0.1). Both the host and port may be speci- fied numerically if you wish to avoid a DNS lookup or do not have an entry for the given port in /etc/services. All remaining arguments are concatenated to form the command(s) that will be sent to the ppp daemon. If any semi-colon characters are found, they are treated as command delimiters, allowing more than one command in a given 'session'. For example: pppctl 3000 set timeout 300; show timeout Do not forget to escape or quote the ';' as it is a special character for most shells. If no command arguments are given, pppctl enters interactive mode, where commands are read from standard input. When reading commands, the editline(3) library is used, allowing command-line editing (with editrc(5) defining editing behaviour). The history size defaults to 20 lines. The following command line options are available: -v Display all data sent to and received from the ppp daemon. Normally, pppctl displays only non-prompt lines received. This option is ignored in interactive mode. -t n Use a timeout of n instead of the default 2 seconds when connecting. This may be required if you wish to control a daemon over a slow (or even a dialup) link. -p passwd Specify the password required by the ppp daemon. If this switch is not used, pppctl will prompt for a password once it has success- fully connected to ppp. ENVIRONMENT
The following environment variables are understood by pppctl when in interactive mode: EL_SIZE The number of history lines. The default is 20. EL_EDITOR The edit mode. Only values of "emacs" and "vi" are accepted. Other values are silently ignored. This environment variable will override the bind -v and bind -e commands in ~/.editrc. EXAMPLES
If you run ppp in -auto mode, pppctl can be used to automate many frequent tasks (you can actually control ppp in any mode except interactive mode). Use of the -p option is discouraged (even in scripts that are not readable by others) as a ps(1) listing may reveal your secret. The best way to allow easy, secure pppctl access is to create a local server socket in /etc/ppp/ppp.conf (in the correct section) like this: set server /var/run/internet "" 0177 This will instruct ppp to create a local domain socket, with srw------- permissions and no password, allowing access only to the user that invoked ppp. Refer to the ppp(8) man page for further details. You can now create some easy-access scripts. To connect to the internet: #! /bin/sh test $# -eq 0 && time=300 || time=$1 exec pppctl /var/run/internet set timeout $time; dial To disconnect: #! /bin/sh exec pppctl /var/run/internet set timeout 300; close To check if the line is up: #! /bin/sh pppctl -p '' -v /var/run/internet quit | grep ^PPP >/dev/null if [ $? -eq 0 ]; then echo Link is up else echo Link is down fi You can even make a generic script: #! /bin/sh exec pppctl /var/run/internet "$@" You could also use pppctl to control when dial-on-demand works. Suppose you want ppp to run all the time, but you want to prevent dial-out between 8pm and 8am each day. However, any connections active at 8pm should continue to remain active until they are closed or naturally time out. A cron(8) entry for 8pm which runs pppctl /var/run/internet set filter dial 0 deny 0 0 will block all further dial requests, and the corresponding 8am entry pppctl /var/run/internet set filter dial -1 will allow them again. SEE ALSO
ps(1), editline(3), editrc(5), services(5), ppp(8) HISTORY
The pppctl utility first appeared in FreeBSD 2.2.5. BSD
June 26, 1997 BSD
All times are GMT -4. The time now is 08:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy