Sponsored Content
Top Forums UNIX for Beginners Questions & Answers UNIX: Executing command using variable Post 303044935 by Raza Ali on Monday 9th of March 2020 09:34:31 AM
Old 03-09-2020
UNIX: Executing command using variable

Hi All,

I have one big script to execute multiple commands based on some condition and log the process.

I am not able to use | there, it is giving below error - refer code: it is small example.

Can we avoid this error ?

Code:
[alepo@a2e-rep-db tmp]$ cat test55.sh
#!/bin/bash
a="df -kh|head -2"
echo "$a"
$a
[alepo@a2e-rep-db tmp]$
[alepo@a2e-rep-db tmp]$ sh test55.sh
df -kh|head -2
df: invalid option -- '|'
Try 'df --help' for more information.
[alepo@a2e-rep-db tmp]$

This works fine.

Code:
[alepo@a2e-rep-db tmp]$ cat test55.sh
#!/bin/bash
a="df -kh"
echo "$a"
$a
[alepo@a2e-rep-db tmp]$
[alepo@a2e-rep-db tmp]$ sh test55.sh
df -kh
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs         24G     0   24G   0% /dev
tmpfs            24G     0   24G   0% /dev/shm
tmpfs            24G   41M   24G   1% /run
tmpfs            24G     0   24G   0% /sys/fs/cgroup
/dev/vda1        99G   23G   72G  24% /
/dev/vdc1       6.9T  2.2T  4.5T  33% /data
tmpfs           4.7G     0  4.7G   0% /run/user/54321
tmpfs           4.7G     0  4.7G   0% /run/user/0
tmpfs           4.7G     0  4.7G   0% /run/user/1000
[alepo@a2e-rep-db tmp]$

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Executing UNIX command from java on NT

Hi - I am totally new to UNIX so please bear with me... I run a java program on Win NT server to do file ftp to UNIX server. I log in, cd, create ftp file on UNIX and quit from my java progam - all works well. Now I want to execute a script on UNIX. At the UNIX 'console'/'shell' (!?) you... (1 Reply)
Discussion started by: CJ Walt
1 Replies

2. Shell Programming and Scripting

taking every variable and executing the command

Hi, I am trying to export some 50 tables and i want to write a loop and execute the script for every table. I did for one table and its running. Can any one help me for setting a loop and running the script for all the tables thanks (6 Replies)
Discussion started by: srichunduru
6 Replies

3. Shell Programming and Scripting

executing *.bat file on windows from Unix box via ftp command

I have created get_list.bat file containing following line: dir /B /O-d >file_list.txt I am executing ftp command from Unix box and transferring get_list.bat file to windows server. In my next ftp command I am trying to execute this test.bat file by entering this line: get_list or by... (9 Replies)
Discussion started by: alx
9 Replies

4. UNIX for Dummies Questions & Answers

Executing a unix command

Hi, I need to execute the following unix command through my java code - zip -e When i execute this command from the command prompt, i am prompted for a password in the following manner - Enter password: Verify password: Is it possible to provide the password inthe first command itself... (5 Replies)
Discussion started by: jacob23
5 Replies

5. UNIX for Advanced & Expert Users

unix script for repeating a command with a variable

Hi need urgent help , for creating unix script . To collect system name,This is command i want to execute n (integer) no. of times for for a differnt IP addresses .IP is variable in every execution. Other string & collecter name is constant . snmpGet %IP% sysName.0 -c <string> -S <datacollecter... (2 Replies)
Discussion started by: langdatyagi
2 Replies

6. Shell Programming and Scripting

bash variable - unix command

I want to just run this command from a bash script and put it in variable. date '+%M' gives the minutes in solaris. (2 Replies)
Discussion started by: photon
2 Replies

7. Shell Programming and Scripting

invoke unix variable in SED command

Hi, I am trying tio invoke unix variable in a sed command like below, but it seems to be failing.. a=1 sed -n '$a,$p' file.txt ### Failing but a=1 sed -n '1,$p' files.txt ### Works fine Please help me to fix this... Thanks in advance (2 Replies)
Discussion started by: vjayraghavan
2 Replies

8. Shell Programming and Scripting

Executing a variable that strores a unix command string

Hi: I have a touble with executing a variable that stores a unix command string. The following would be excuted fine: command='ls -l' `echo $command` However, the following gives me an error: command='(uuencode file1 file1; uuencode file2 file2) | mailx email_id' `echo... (1 Reply)
Discussion started by: sagewise
1 Replies

9. UNIX for Advanced & Expert Users

Error executing sqlcmd command through UNIX

Hi All, I am trying to execute a set of sql statements in sql server 2008 using the sqlcmd command in unix and passing the query in the "input" parameter. It is giving me an error "incorrect syntax near 2014". The below statement is giving an error : declare date_val datetime, ... (4 Replies)
Discussion started by: Rahul Raj
4 Replies

10. Solaris

How to find IP of user machine executing a particular UNIX command?

Hello, Our applications are deployed in SunOS 5.10 servers. All the team members use a same username/pwd to login to the box. Very often we face issue were we could see that weblogic server instance are KILLED and we are not able to trace who executed kill command. All team members use PUTTY to... (2 Replies)
Discussion started by: santtarius
2 Replies
tmpfs(5)						   Debian Administrator's Manual						  tmpfs(5)

NAME
tmpfs - variables that configure tmpfs filesystems mounted during boot DESCRIPTION
The /etc/default/tmpfs file contains variable settings in POSIX format: VAR=VAL Only one assignment is allowed per line. Comments (starting with '#') are also allowed. This file is for the configuration of tmpfs filesystems mounted in early boot, before filesystems from /etc/fstab are mounted. This cur- rently includes the filesystems /run, /run/lock, /run/shm and /tmp. /run is required to be a tmpfs on systems supporting tmpfs mounts. /run/lock and /run/shm may be separate tmpfs mounts, useful for enforcing separate size limits. /tmp is not required to be a tmpfs, but is mounted as a tmpfs by default. /run Previously configured using RAMRUN in /etc/default/rcS, /run is now always mounted as a ram file system (tmpfs). The size of the tmpfs can be controlled using TMPFS_SIZE and RUN_SIZE. If desired, the defaults may also be overridden with an entry in in /etc/fstab, for example: tmpfs /run tmpfs nodev,nosuid,size=10%,mode=755 0 0 The contents of /run will always be lost on system reboot, and it it is no longer explicitly cleaned at boot. Packages can not expect directories in /run to exist after boot. Packages expecting this are buggy and need to be fixed. Note that /run was previ- ously /var/run, and a compatibility symlink or bind mount will be created to allow the old path to continue to function. /run/lock Previously configured using RAMLOCK in /etc/default/rcS. Configured using RAMLOCK, TMPFS_SIZE and LOCK_SIZE. If desired, the defaults may also be overridden with an entry in in /etc/fstab, for example: tmpfs /run/lock tmpfs nodev,noexec,nosuid,size=52428800,mode=1777 0 0 Note that irrespective of these settings, /run/lock will be located on a tmpfs, either one mounted on /run/lock (if RAMLOCK=yes) or one mounted on /run (if RAMLOCK=no), and as a result the contents of /var/lock will always be lost on system reboot, and it it is no longer explicitly cleaned at boot. Packages can not expect directories in /var/lock to exist after boot. Packages expecting this are buggy and need to be fixed. Note that /run/lock was previously /var/lock, and a compatibility symlink or bind mount will be created to allow the old path to continue to function. /run/shm Previously configured using RAMSHM in /etc/default/rcS. Note that the setting in /etc/default/rcS, if present, will still be used, but the setting in /etc/default/tmpfs will take precedence if enabled. Configured using RAMSHM, TMPFS_SIZE and SHM_SIZE. If desired, the defaults may also be overridden with an entry in in /etc/fstab, for example: tmpfs /run/shm tmpfs nosuid,nodev,size=40%,mode=1777 0 0 Packages can not expect directories in /run/shm to exist after boot. Note that /run/shm was previously /dev/shm, and a compatibil- ity symlink or bind mount will be created to allow the old path to continue to function. If an fstab entry for /dev/shm exists instead of /run/shm, then /dev/shm will continue to be used; note that this is only needed for users of newer versions of the Oracle database, which contain a buggy check for /dev/shm. /tmp Previously configured using RAMTMP in /etc/default/rcS. Note that the setting in /etc/default/rcS, if present, will still be used, but the setting in /etc/default/tmpfs will take precedence if enabled. Configured using RAMTMP, TMPFS_SIZE and TMP_SIZE. If desired, the defaults may also be overridden with an entry in in /etc/fstab, for example: tmpfs /tmp tmpfs nodev,nosuid,size=20%,mode=1777 0 0 Packages can not expect directories in /tmp to exist after boot. OPTIONS
The following variables can be set. Enabling or disabling tmpfs mounts The following options enable specific mounts (with the exception of /run) to be enabled or disabled. Note that the addition of an entry to /etc/fstab for any of the following will enable the mount unconditionally, overriding the setting here. RAMLOCK Mount /run/lock as a tmpfs (separately from /run). Defaults to yes; set to no to disable (/run/lock will then be part of the /run tmpfs, if available). RAMSHM Mount /run/shm as a tmpfs (separately from /run). Defaults to yes; set to no to disable (/run/shm will then be part of the /run tmpfs, if available). RAMTMP Mount /tmp as a tmpfs. Defaults to no; set to yes to enable (/tmp will be part of the root filesystem if disabled). /tmp may also be configured to be a separate mount in /etc/fstab, which will override the RAMTMP setting. Configuring size limits for tmpfs mounts The following options configure size limits for tmpfs mounts. Note that the addition of an entry to /etc/fstab will override any of the limits specified here. The following _SIZE variables are the maximum size (in bytes) that tmpfs filesystems can use. The size will be rounded down to a multiple of the page size, 4096 bytes. If no size is set, TMPFS_SIZE will be used as the default. More complex mount options may be used by the creation of a suitable entry in /etc/fstab. For example: tmpfs /run tmpfs size=10% 0 0 is equivalent to RUN_SIZE=10% and will override the RUN_SIZE setting. This will allow additional options such as nr_blocks and nr_inodes to be used, and also adjustment of the mode, nodev, nosuid, noexec options should any change from the defaults be necessary. TMPFS_SIZE Maximum size for all tmpfs filesystems if no specific size is provided. The default is 20%VM (20% of virtual memory, including swap space). If no value is provided here, the kernel default (50% RAM) will be used. Note that the "%VM" suffix may be used in this and all the _SIZE settings below, but may not be used in /etc/fstab (the absolute size is calculated by the init scripts). RUN_SIZE Maximum size of /run (was previously /var/run). The default is 10% core memory; the size required varies widely depending upon the demands of the software being run; this heuristic scales /run usage on system size. Samba in particular has been seen to use at least 50MiB in a large heavily used server. Typical usage is hundreds of KiB, maximum is tens of MiB. LOCK_SIZE Maximum size of /run/lock (was previously /var/lock). Defaults to 5242880 (5 MiB). Typical usage: tens of KiB; maximum hundreds of KiB. The default of 5 MiB should ensure the limit is never reached. SHM_SIZE Maximum size of /run/shm (was previously /dev/shm). No default size; the size required varies widely depending upon the demands of the software being run. TMP_SIZE Maximum size of /tmp. No default size. Emergency overflow /tmp If the amount of free space on the root filesystem falls below a certain size, a tmpfs will be mounted on /tmp (irrespective of the RAMTMP setting, which this overrides). This is to permit logins when there would otherwise be too little free space for this to be possible. TMP_OVERFLOW_LIMIT Mount a tmpfs on /tmp if the amount of free space on the root filesystem is below the specified limit at boot time (default 1024 KiB). AUTHOR
Roger Leigh <rleigh@debian.org> SEE ALSO
mount(8), rcS(5). 18 Feb 2012 tmpfs(5)
All times are GMT -4. The time now is 02:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy